Postback not behaving as expected

Discussion in 'ASP .Net' started by blinton25, Dec 10, 2008.

  1. blinton25

    blinton25 Guest

    Hi,

    Trying some sample code at:

    http://www.w3schools.com/aspnet/aspnet_events.asp (The Page.IsPostBack
    Property)

    I believe that the first time the page is loaded the date should be printed,
    but when I click the button, the date will not be shown. However the date
    continues to be shown.

    Any idea why this is occuring?
    blinton25, Dec 10, 2008
    #1
    1. Advertising

  2. Will be much easier if you can paste the code that you are using.

    Regards,

    Trevor Benedict
    MCSD

    "blinton25" <> wrote in message
    news:...
    > Hi,
    >
    > Trying some sample code at:
    >
    > http://www.w3schools.com/aspnet/aspnet_events.asp (The Page.IsPostBack
    > Property)
    >
    > I believe that the first time the page is loaded the date should be
    > printed,
    > but when I click the button, the date will not be shown. However the date
    > continues to be shown.
    >
    > Any idea why this is occuring?
    Trevor Benedict, Dec 10, 2008
    #2
    1. Advertising

  3. blinton25

    Jeff Dillon Guest

    But the time won't change, as the instructions point out

    "blinton25" <> wrote in message
    news:...
    > Hi,
    >
    > Trying some sample code at:
    >
    > http://www.w3schools.com/aspnet/aspnet_events.asp (The Page.IsPostBack
    > Property)
    >
    > I believe that the first time the page is loaded the date should be
    > printed,
    > but when I click the button, the date will not be shown. However the date
    > continues to be shown.
    >
    > Any idea why this is occuring?
    Jeff Dillon, Dec 10, 2008
    #3
  4. blinton25

    blinton25 Guest

    Hi,

    Ok, thanks. I actually used:

    <%@ Page EnableViewState="false" %>

    Thanks again.

    "Mark Rae [MVP]" wrote:

    > "blinton25" <> wrote in message
    > news:...
    >
    > > I believe that the first time the page is loaded the date should be
    > > printed,
    > > but when I click the button, the date will not be shown. However the date
    > > continues to be shown.
    > >
    > > Any idea why this is occuring?

    >
    > This is default behaviour - ViewState is preserving the value across the
    > postback.
    >
    > If you don't want it to, do this:
    > <asp:Label ID="lbl1" runat="server" EnableViewState="False" />
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    blinton25, Dec 10, 2008
    #4
  5. blinton25

    Jeff Dillon Guest

    No need to worry about viewstate. If you read the instructions, you will
    note that the Date/Time is supposed to show on PostBack, but the time won't
    change

    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "blinton25" <> wrote in message
    > news:...
    >
    >>>> Any idea why this is occuring?
    >>>
    >>> This is default behaviour - ViewState is preserving the value across the
    >>> postback.
    >>>
    >>> If you don't want it to, do this:
    >>> <asp:Label ID="lbl1" runat="server" EnableViewState="False" />

    >>
    >> Ok, thanks. I actually used:
    >>
    >> <%@ Page EnableViewState="false" %>

    >
    > That will disable ViewState for the entire page rather than just for
    > individual controls...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    Jeff Dillon, Dec 10, 2008
    #5
  6. The reason I asked for the code was to make sure the OP was using the code
    exactly as-is. sometimes copy-paste can create issues in itself.

    Regards,

    Trevor Benedict

    "Mark Rae [MVP]" <> wrote in message
    news:%...
    > "Trevor Benedict" <> wrote in message
    > news:...
    >
    > [top-posting corrected]
    >
    >>> Trying some sample code at:
    >>>
    >>> http://www.w3schools.com/aspnet/aspnet_events.asp (The Page.IsPostBack
    >>> Property)

    >>
    >> Will be much easier if you can paste the code that you are using.

    >
    > He's using the code in the web page that he said he was using...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    Trevor Benedict, Dec 11, 2008
    #6
  7. blinton25

    Sam Guest

    On Dec 10, 12:56 pm, blinton25 <>
    wrote:
    > Hi,
    >
    > Trying some sample code at:
    >
    > http://www.w3schools.com/aspnet/aspnet_events.asp (The Page.IsPostBack
    > Property)
    >
    > I believe that the first time the page is loaded the date should be printed,
    > but when I click the button, the date will not be shown. However the date
    > continues to be shown.
    >
    > Any idea why this is occuring?


    I think you are misunderstanding the example. The date will always be
    shown, but as you can verify the date and time value displayed never
    changes, because it is only set on the first time the page is loaded.
    If you refresh the page, you'll see the date and time value change.
    So the label value is set once on the initial page load and is never
    changed again with subsequent post backs.

    Thanks,

    Sam
    Sam, Dec 11, 2008
    #7
  8. blinton25

    blinton25 Guest

    Hello,

    Thanks for your responses, they allowed me to understand the original
    example and then modify it.

    "Jeff Dillon" wrote:

    > No need to worry about viewstate. If you read the instructions, you will
    > note that the Date/Time is supposed to show on PostBack, but the time won't
    > change
    >
    > "Mark Rae [MVP]" <> wrote in message
    > news:...
    > > "blinton25" <> wrote in message
    > > news:...
    > >
    > >>>> Any idea why this is occuring?
    > >>>
    > >>> This is default behaviour - ViewState is preserving the value across the
    > >>> postback.
    > >>>
    > >>> If you don't want it to, do this:
    > >>> <asp:Label ID="lbl1" runat="server" EnableViewState="False" />
    > >>
    > >> Ok, thanks. I actually used:
    > >>
    > >> <%@ Page EnableViewState="false" %>

    > >
    > > That will disable ViewState for the entire page rather than just for
    > > individual controls...
    > >
    > >
    > > --
    > > Mark Rae
    > > ASP.NET MVP
    > > http://www.markrae.net

    >
    >
    >
    blinton25, Dec 14, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Kafieh
    Replies:
    7
    Views:
    2,485
    Roedy Green
    May 19, 2004
  2. William Krick
    Replies:
    4
    Views:
    77,848
    rt19983
    Dec 18, 2008
  3. Skip Montanaro

    sys._getframe() not behaving as expected

    Skip Montanaro, Dec 1, 2003, in forum: Python
    Replies:
    0
    Views:
    352
    Skip Montanaro
    Dec 1, 2003
  4. Replies:
    1
    Views:
    343
    David
    Apr 16, 2007
  5. Steve Richter
    Replies:
    2
    Views:
    599
    Steve Richter
    May 29, 2007
Loading...

Share This Page