Browser History Problem

Last post 04-25-2008 1:09 AM by sujoyupadhyay. 17 replies.

Sort Posts:

  • Re: Browser History Problem

    04-24-2008, 9:15 AM
    • Loading...
    • roman_t
    • Joined on 04-21-2008, 5:36 PM
    • Ukraine
    • Posts 6

    Finally I investigated one more "ugly bug" with Back button in Internet Explorer - really strange behavior.

    There is the "bug" description. Consider you are on a.aspx page and there are 2 input boxes both inside UpdatePanel. EventValidation is ON for this page. Then you click some button on a.aspx which causes asynchronous postback and hides one of the text boxes. Then you click on any beforehand prepared anchor which navigates to b.aspx. And now if you click Back button Internet Explorer will restore POST data from his cache. This restored POST data contains two input boxes (+ VIEVSTATE, EVENTVALIDATION, ...) but EVENTVALIDATION value contains the most recent value which was written by last async postback - validation data for only visible input box. Now try to do some postback - Event Validation Failed exception is raised.

    I have never knew about this behavior early, but now I understand why History control under IE "sometimes" throws "Event Validation Failed" exception when navigating Back within another page. Thankfully there are not very elegant but effective solution to this problem: prevent Page from being cached by IE. GET request will be triggered when you click Back button and this GET request will deliver valid POST data for further POST requests.

      HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

     
  • Re: Browser History Problem

    04-24-2008, 10:43 AM
    • Loading...
    • roman_t
    • Joined on 04-21-2008, 5:36 PM
    • Ukraine
    • Posts 6

    Earlier in this post I mentioned that we can "force" Internet Explorer to forget all history items for page a.aspx when navigating backward from b.aspx  by simply adding such code to ButtonClick method:
      

    ScriptManager.RegisterStartupScript(this, GetType(), "hmmm", "", true);
       But now I investigated more simple steps to reproduce this horrible IE bug. Add somewhere on a.aspx  <input type="button" onclick="foo()" /> and implement foo() JavaScript function as follows:

           

            var scriptElement = document.createElement('SCRIPT');
            document.getElementsByTagName('HEAD')[0].appendChild(scriptElement);
     

    Now it is enough at some moment to click this button to make History control much more useless under IE :( Maybe there is even more simpler script to cause described problem. Above script describes what ScriptManager does when ScriptManager.RegisterStartupScript() is called. You can ensure that  document.getElementsByTagName('HEAD')[0].appendChild(document.createElement("SPAN")) also breaks History.

  • Re: Browser History Problem

    04-25-2008, 1:09 AM

    <html>

    <head>

    <script language="javascript">

    alert("Testing");

    </script>

    </head>

    </html>

Page 2 of 2 (18 items) < Previous 1 2