How do I get a page to maintain control states?

Discussion in 'ASP .Net' started by Tom wilson, Feb 16, 2005.

  1. Tom wilson

    Tom wilson Guest

    This is the same topic as the thread above, "Dealing with the Back
    button". I'm getting nowhere. The closest I've come is a sample left
    for me:

    <%@ Page Language="vb" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    </head>
    <body>
    <form runat="server" ID="Form1">
    <p>
    &nbsp;<asp:TextBox id="TextBox1"
    runat="server"></asp:TextBox>
    </p>
    <p>
    &nbsp;<asp:Button id="Button1" runat="server"
    Text="Button"></asp:Button>
    </p>
    </form>
    </body>
    </html>

    1 - Load the page, enter something in the text box.
    2 - Hit submit
    3 - Click Back
    4 - The string you entered remains.

    When I put this code, in its entirety, into a new .aspx page and run
    it, the textbox is blank after hitting the back button.

    Why, and how can I prevent it? (before I go completely insane)

    Thanks!
     
    Tom wilson, Feb 16, 2005
    #1
    1. Advertising

  2. Tom wilson

    Patrice Guest

    I don't see what difference you make between point 1 to 4 and the later
    scenario (not clear if you used submit before using the back button).

    IMO :
    - if something is wrong I would redisplay the whole form with the error
    message so that the user doesn't even have to use the back button. Keep in
    mind that you would rely here on a client side behavior that the user could
    have altered (by changing its IE settings).

    - for now I have the behavior you described in point 1 to 4. Could it be a
    problem with your cache ? I would try to add a date/time information to the
    page to see if the page with blank fields comes from the IE cache or if IE
    gets it once again from the server. It could be also a IE settings. For now
    it looks liike that when you using the back button, IE gets the page again
    (AFAIK it was also the behavior on old IE releases, whcih version are you
    using).

    Good luck.

    Patrice


    --

    "Tom wilson" <> a écrit dans le message de
    news:p...
    > This is the same topic as the thread above, "Dealing with the Back
    > button". I'm getting nowhere. The closest I've come is a sample left
    > for me:
    >
    > <%@ Page Language="vb" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <html>
    > <head>
    > </head>
    > <body>
    > <form runat="server" ID="Form1">
    > <p>
    > &nbsp;<asp:TextBox id="TextBox1"
    > runat="server"></asp:TextBox>
    > </p>
    > <p>
    > &nbsp;<asp:Button id="Button1" runat="server"
    > Text="Button"></asp:Button>
    > </p>
    > </form>
    > </body>
    > </html>
    >
    > 1 - Load the page, enter something in the text box.
    > 2 - Hit submit
    > 3 - Click Back
    > 4 - The string you entered remains.
    >
    > When I put this code, in its entirety, into a new .aspx page and run
    > it, the textbox is blank after hitting the back button.
    >
    > Why, and how can I prevent it? (before I go completely insane)
    >
    > Thanks!
    >
     
    Patrice, Feb 16, 2005
    #2
    1. Advertising

  3. Tom wilson

    Tom wilson Guest

    ">- if something is wrong I would redisplay the whole form with the
    error message so that the user doesn't even have to use the back
    button."

    That sounds logical, doesn't it? My main app works this way. You get
    your form, fill stuff out and submit. The page returns to the browser
    with red error texts above each 'errored' control. Its a work of art.
    You can submit repeatedly until all errors disappear. I'm proud.

    But click back anywhere during this process, even after 5 submits, the
    page is returned blank. Come on, you know SOMEbody is going to click
    the back button and call me up, pissed.

    So I tried your time example as suggested below:

    - Load form. Time is: 2:53:12
    - Enter text, submit
    - Time is 2:53:33
    - Click "Back"
    - Time is: 2:53:12

    I assume the page is coming from IE's cache cause the time is the same
    when going back. If it came from the server the time would be past
    2:53:33, right?

    So this means... asp.net pages are not capable of maintaining state?
    :)

    Or that IE is somehow killing the page state when it reloads the page
    from its cache?

    Nothing is making any sense.

    (thx for the reply!)




    On Wed, 16 Feb 2005 20:27:11 +0100, "Patrice" <>
    wrote:

    >I don't see what difference you make between point 1 to 4 and the later
    >scenario (not clear if you used submit before using the back button).
    >
    >IMO :
    >- if something is wrong I would redisplay the whole form with the error
    >message so that the user doesn't even have to use the back button. Keep in
    >mind that you would rely here on a client side behavior that the user could
    >have altered (by changing its IE settings).
    >
    >- for now I have the behavior you described in point 1 to 4. Could it be a
    >problem with your cache ? I would try to add a date/time information to the
    >page to see if the page with blank fields comes from the IE cache or if IE
    >gets it once again from the server. It could be also a IE settings. For now
    >it looks liike that when you using the back button, IE gets the page again
    >(AFAIK it was also the behavior on old IE releases, whcih version are you
    >using).
    >
    >Good luck.
    >
    >Patrice
     
    Tom wilson, Feb 16, 2005
    #3
  4. Tom wilson

    Chad Devine Guest

    You do not have:
    <%@ Page EnableViewState="True" %>
    at the top of your .aspx page.

    You do have:
    <%@ Page Language="vb" %>

    So just add on the EnableViewState like this:
    <%@ Page Language="VB" EnableViewState="True" %>

    That will enable your page to keep the form information.
     
    Chad Devine, Feb 16, 2005
    #4
  5. Unless EnableViewState has been explicitly set to "false"
    in web.config, the default setting is "true", so setting it to
    "true" should not affect the page's ViewState settings.

    But, maybe it *was* set to "false" in web.config... :)



    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    =====================

    "Chad Devine" <> wrote in message
    news:...
    > You do not have:
    > <%@ Page EnableViewState="True" %>
    > at the top of your .aspx page.
    >
    > You do have:
    > <%@ Page Language="vb" %>
    >
    > So just add on the EnableViewState like this:
    > <%@ Page Language="VB" EnableViewState="True" %>
    >
    > That will enable your page to keep the form information.
    >
     
    Juan T. Llibre, Feb 16, 2005
    #5
  6. Tom wilson

    Tom wilson Guest

    OMG, it works.

    This tiny example works, my main app does not.

    But that's the solution to my small example. You may now feel
    intellectually superior. :)

    for x=1 to 1000000
    response.write("THANKS!!!!<BR>")
    Next



    On 16 Feb 2005 13:00:54 -0800, "Chad Devine" <>
    wrote:

    >You do not have:
    ><%@ Page EnableViewState="True" %>
    >at the top of your .aspx page.
    >
    >You do have:
    ><%@ Page Language="vb" %>
    >
    >So just add on the EnableViewState like this:
    ><%@ Page Language="VB" EnableViewState="True" %>
    >
    >That will enable your page to keep the form information.
     
    Tom wilson, Feb 16, 2005
    #6
  7. Tom wilson

    Chad Devine Guest

    Or perhaps no web.config exists, which could also result in this
    problem.
     
    Chad Devine, Feb 16, 2005
    #7
  8. Hmm...

    It's set in machine.config ( in both v1.1 and v2.0 ).
    I don't remember about v1.0, but think it was.

    It's interesting to note that setting it to "true" *did* work,
    so *someone* must have fiddled with that setting ... ;-)



    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    =====================

    "Chad Devine" <> wrote in message
    news:...
    > Or perhaps no web.config exists, which could also result in this
    > problem.
     
    Juan T. Llibre, Feb 16, 2005
    #8
  9. Tom wilson

    Tom wilson Guest

    You would think. There's nothing about viewstate in web.config, I
    assume that means its enabled by defualt. I have checked many times,
    the properties of the form and the controls and all their viewstate
    properties are set to True. But this example (single textbox) would
    not work....

    *WITH Internet Explorer ONLY*

    Interesting, huh? Firefox and Netscape 7.1, after clicking submit and
    then clicking Back, retained the value in the textbox. IE did not,
    until I added that line below to enable the viewstate.

    My main app does something similar but it's far more complicated; it
    does a submit postback, checks for entry errors and returns the page
    with error texts inserted into the pageholder sequence. It works
    perfectly going forward but go back and everything is lost.

    I still have to do somthing about that, I can't have users killing
    page after page of data entry with a single click. Usually it's "Page
    has expired", at which point you have to go "Back" until you're at the
    first iteration of the page. Hmm...




    On Wed, 16 Feb 2005 17:27:18 -0400, "Juan T. Llibre"
    <> wrote:

    >Unless EnableViewState has been explicitly set to "false"
    >in web.config, the default setting is "true", so setting it to
    >"true" should not affect the page's ViewState settings.
    >
    >But, maybe it *was* set to "false" in web.config... :)
    >
    >
    >
    >Juan T. Llibre
    >ASP.NET MVP
    >http://asp.net.do/foros/
    >Foros de ASP.NET en Español
    >=====================
    >
    >"Chad Devine" <> wrote in message
    >news:...
    >> You do not have:
    >> <%@ Page EnableViewState="True" %>
    >> at the top of your .aspx page.
    >>
    >> You do have:
    >> <%@ Page Language="vb" %>
    >>
    >> So just add on the EnableViewState like this:
    >> <%@ Page Language="VB" EnableViewState="True" %>
    >>
    >> That will enable your page to keep the form information.
    >>

    >
     
    Tom wilson, Feb 16, 2005
    #9
  10. Tom wilson

    Chad Devine Guest

    You're right Juan, which means this is truly a strange problem. Anyway,
    glad it worked... now to figure out why it worked, ha.
     
    Chad Devine, Feb 16, 2005
    #10
  11. Tom wilson

    Chad Devine Guest

    >From what I know about viewstate, if your form is posting to another
    page, all the view state information will be lost. So, in that case you
    may have to use session state variables or something... Perhaps Juan
    knows of something easier than throwing all form fields into session
    state.
     
    Chad Devine, Feb 16, 2005
    #11
  12. Tom wilson

    Patrice Guest

    Humm... Is it solved ?

    Sounds really strange to me it was the viewstate as when the page is loaded
    from the cache there is AFAIK no code that runs...

    I disabled viewstate on my test page and still have the same behavior (i.e.
    when the page is submitted and when I click on the back button, form fields
    are left intact). I'm using IE6.

    Patrice

    --

    "Tom wilson" <> a écrit dans le message de
    news:...
    > OMG, it works.
    >
    > This tiny example works, my main app does not.
    >
    > But that's the solution to my small example. You may now feel
    > intellectually superior. :)
    >
    > for x=1 to 1000000
    > response.write("THANKS!!!!<BR>")
    > Next
    >
    >
    >
    > On 16 Feb 2005 13:00:54 -0800, "Chad Devine" <>
    > wrote:
    >
    > >You do not have:
    > ><%@ Page EnableViewState="True" %>
    > >at the top of your .aspx page.
    > >
    > >You do have:
    > ><%@ Page Language="vb" %>
    > >
    > >So just add on the EnableViewState like this:
    > ><%@ Page Language="VB" EnableViewState="True" %>
    > >
    > >That will enable your page to keep the form information.

    >
     
    Patrice, Feb 17, 2005
    #12
  13. Tom wilson

    Tom wilson Guest

    Actually, no. My main app works flawlessly in Netscape and Firefox.
    In IE, the back button will lose all data every time. See my post
    farther down. :)


    On Thu, 17 Feb 2005 11:09:59 +0100, "Patrice" <>
    wrote:

    >Humm... Is it solved ?
    >
    >Sounds really strange to me it was the viewstate as when the page is loaded
    >from the cache there is AFAIK no code that runs...
    >
    >I disabled viewstate on my test page and still have the same behavior (i.e.
    >when the page is submitted and when I click on the back button, form fields
    >are left intact). I'm using IE6.
    >
    >Patrice
     
    Tom wilson, Feb 17, 2005
    #13
    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. John
    Replies:
    2
    Views:
    328
    MS News \(MS ILM\)
    Aug 20, 2003
  2. Edwin Knoppert

    Maintain Treeview's expand states between pages

    Edwin Knoppert, Nov 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    600
    Edwin Knoppert
    Nov 7, 2005
  3. Kourosh
    Replies:
    3
    Views:
    961
    Steven Saunderson
    Jun 3, 2006
  4. =?Utf-8?B?cnViZW5j?=

    views or states of a passwordrecovery control

    =?Utf-8?B?cnViZW5j?=, Oct 18, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    302
    =?Utf-8?B?cnViZW5j?=
    Oct 18, 2007
  5. Bobby Edward
    Replies:
    3
    Views:
    324
    Cowboy \(Gregory A. Beamer\)
    Oct 28, 2008
Loading...

Share This Page