locked
AJAX History Points Lost When Returning to Previous Page RRS feed

  • Question

  • User1615932232 posted

    I am attempting to retrofit a web application that had a rudimentary,
    yet mostly effective navigation infrastructure that, when properly
    utilized, allowed navigating forward and backward through AJAX states
    and other pages through the use of additional <asp:Button> objects
    labeled "Back" to perform special code for restoring previous states.
    There was an elaborate stack push and pop algorithm for this.  The
    effect was very similar to what is described in Diagram 1 (AStatex
    refers to an AJAX related state of the page).  The reason for this is
    so that it takes away the reliance on the contrived Back button and so
    that accidentally hitting the browser's back button or hitting the
    Backspace key won't cause a loss of state.

    Diagram 1
    Page1 -> Page2.AState1 -> Page2.AState2 -> Page2.AState3 -> Page3
    Using contrived Back button
    Page3 -> Page2.AState3 -> Page2.AState2 -> Page2.AState1 -> Page1

    The intent is to utilize the ASP.NET 3.5 ability to add history points
    via the bookmarking feature of the browser.  I have read a non-trivial
    amount about this technique, however the problem I am experiencing is
    that when either redirecting to a new page, performing a cross-page
    postback, or some other way of leaving a page, the history points
    programatically added for the previous page are now lost, causing the
    previous page's AJAX state history to be lost.   All pages that will implement this will implement an INavigableWebForm interface that requires some key methods.  I have the one and only ScriptManager object in the Master Page and the Master Page handles OnNavigate event by then calling one of those interface methods in the page to restore values to controls and handle hiding or displaying controls.

    Referring to Diagram 2, I can return to Page2 with the last state
    restored, but if
    I hit the browser's back button again, it takes me back to Page1 instead of the previous state on Page2.

    Diagram 2
    Page1 -> Page2.AState1 -> Page2.AState2 -> Page2.AState3 -> Page3
    Using AJAX History Points, the ScriptManager.OnNavigate method and
    Browser's back button
    Page3 -> Page2.AState3 -> Page1

    I had thought about attempting to use a combination of pushing state
    information onto the original stack object so that it could be
    restored in instances of navigating back to a different page, such as
    Page2 and somehow have all of the browser's history points remaining
    intact for Page2.  The problem is that you cannot sporadically (or
    asynchronously) add history points, so even if I had the ability to
    retrieve the history from data popped from the stack, I can't repopulate the missing
    history points.

    Is there a way to prevent the loss of the previous page's history
    points?

    Thursday, January 14, 2010 3:45 PM

All replies

  • User555306248 posted

    It actually depends on how the caching is set on the browser.  You can add directives to your page to try to make sure caching doesn't occur (check this out, and this) -- which will give you full control of what happens when the user pushes the back button.

    With IE7 and default settings (my setup) page_load always gets hit when the back button is clicked.

    More

    http://www.nikhilk.net/BackButtonSupport.aspx

    Thursday, January 14, 2010 9:52 PM
  • User1615932232 posted

    Hey Chetan,

    Thanks for the reply.  Unfortunately, this doesn't really address my issue.  There does not appear to be a way to maintain the history beyond a single page.  Once a page is left, the only thing that remains is a path back to the last state of the previous page.  You cannot then step back into previous incremental displays of that page.  Refer to my "diagrams" in the original post for more detail.

    A co-worker just made a good suggestion that should have been obvious to me.  Instead of navigating to a new page, as in Page3, open a new browser window or tab posting the required info to the new page.  As long as I can retain the info in session variables across those tabs or windows then I can leave the previous page, Page2, open and retain the necessary information.  This is not ideal, but may be a good work-around.  If this works out I'll try to update this thread.

    JT

    Tuesday, January 19, 2010 10:37 AM
  • User-825244285 posted

    Did anyone find this solution even i am getting same issue, please help

    Friday, April 20, 2012 2:28 AM
  • User-213159973 posted

    You can use localStorage, that in the first page store you data and at any other page you get your again.

    Wednesday, April 29, 2015 8:52 AM