Contact Sales: +1-888-365-2779
Community & Support
Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Ajax > Ajax, ViewState and Firefox
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Ajax, ViewState and Firefox

Feed from this thread
  • Aaron avatar

    Posted on Jul 12, 2006 (permalink)

    Hi guys,

    I think that this is more of a problem with Firefox than it is with r.a.d. ajax, but this seems like the most likely place I'll find an answer (googling hasn't helped much).

    Many pages seem to be heavily dependent on ViewState - for example, anything with an editable gridview.  Another common example for me is overriding the LoadViewState and SaveViewState methods to store some extra information, and using that information to dynamically load different user controls.

    Of course it all works fine in postback mode, and works fine in callback mode as long as you don't refresh.  In Internet Explorer, if you refresh, you lose all the state and have to start over (so for example if you were editing a row in a gridview, you lose the edits and the editing gets turned off).  I expect this, more or less - I know that refresh and forward/back don't play nice with Ajax and that's a fairly acceptable loss for now.

    Firefox makes the problem a bit worse, though.  I think this has something to do with the browser attempting to save the values of form controls on a Reload, which might possibly include the hidden ViewState field or the event fields.  I'm not exactly sure, but all I know is that in Firefox, if you do something that modifies the viewstate, then reload, the next callback after reload ends up giving an "invalid viewstate" YSOD.

    The easiest example is a GridView.  Throw a gridview inside an ajax panel and add the edit/update command buttons and event handlers.  Then start editing a record, and reload the page without updating.  If you try to edit a record again, it takes you to a yellow screen with "The state information is corrupted".

    Again, seeing as how this doesn't occur in IE, I'm tempted to believe it has to do with the way Firefox handles form input on page reloads.  If it's trying to preserve what's in the viewstate field, that would go a long way toward explaining the error, but unfortunately doesn't help solve it.  A while ago I tried overriding the Render event, using a regex to pick up the encoded ViewState string, and append a JavaScript to "force" the ViewState field to be updated on the first page load (i.e. a reload).  This sort of worked but in the end didn't really solve the problem and created other weird problems.

    I even added a page adapter to store ViewState in SessionState, but it doesn't solve the problem either.  There's still a client-side ViewState field and there's still data inside it, just a lot less data - and whatever data IS inside it seems to be what's causing the yellow screen.

    So essentially I'm at a loss for answers.  I'm not sure how to get Firefox to behave itself, or how to code around its strange behaviour to compensate.

    Has anybody else experienced this?  Has anybody discovered a workaround?  Is it even possible to address this problem in the r.a.d. controls themselves, or in some custom code, or is this something that's in the court of Firefox developers?

    Thanks,
    Aaron

  • Giuseppe Giuseppe admin's avatar

    Posted on Jul 14, 2006 (permalink)


    Hi Aaron,

    Thank you for contacting us.

    To the best of our knowledge, when you try a page refresh with F5, Firefox keeps the form values. As a possible workaround, we would suggest you use the CTRL + F5 combination.In this way, no form values are preserved.


    Regards,

    Manuelthe telerik team

  • Aaron avatar

    Posted on Jul 14, 2006 (permalink)

    That works as long as I'm the only person using the site. :-)

    I don't suppose there's any way to get Firefox to do that through code?

  • Giuseppe Giuseppe admin's avatar

    Posted on Jul 14, 2006 (permalink)

    Hi Aaron,

    You are right -- there is no easy way to restrict the users from refreshing the page with CTRL + F5 instead of using F5 . We are researching for possible workarounds but as you noted this is a general Firefox issue that is not directly related to the r.a.d.controls suite and at the moment we are unsure whether it could be dealt with at all.


    Greetings,
    Manuel
    the telerik team

  • Richard Brown avatar

    Posted on Nov 2, 2006 (permalink)

    Hi,

    Has there been any further thought on this topic? I too get this problem, on Firefox only, whereby if someone goes "back" to a page using the browser buttons, then clicks a button within an AJAX panel i get the "The state information is invalid for this page and might be corrupted" error page.

    Obviously a lot of users still use the back button, so i fear this could be quite an issue.

    Thanks,

    Richard.

  • Giuseppe Giuseppe admin's avatar

    Posted on Nov 3, 2006 (permalink)

    Hi Richard,

    Unfortunately we have not made any progress on this Firefox-specific issue to this moment. In fact we have not received many requests recently on this issue granted that the Ajax technology inherently does not play well with the browser Back button. However, we are ready to take a peek at your code in case anything could be done to alleviate the problem.


    Regards,
    Manuel
    the telerik team

  • Richard Brown avatar

    Posted on Nov 4, 2006 (permalink)

    Hi,

    This is obviously a bit of a concern for me... the Back button is still heavily used by web browsers, so i want a simple way to catch the error and refload the page without the corrupt state information.

    I've taken the following approach so far:

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

    If Server.GetLastError.GetType.Name = "HttpException" Then

    Dim ex As HttpException = Server.GetLastError

    If ex.ErrorCode = -2147467259 And ex.Message = "The state information is invalid for this page and might be corrupted." Then

    Response.Redirect(Request.Url.PathAndQuery) ' redirect to same page.

    Exit Sub

    End If

    End If


    This works fine when the user clicks on a standard form button on the problem page. However, my problem now is that if the user clicks on an AJAX element, the response.redirect does not work and leaves the AJAX in a hang mode, with my AJAX loading panel showing. How do i get around this?

    Thanks,

    Richard.

  • Aaron avatar

    Posted on Nov 4, 2006 (permalink)

    I could be wrong since I'm just a user here, but I think I see the problem with that global exception handler.  The exceptions are actually being generated asynchronously and r.a.d. Ajax is simply catching them and displaying them client-side.  Interrupting that cycle is probably going to make things worse, not better - you're tricking the Ajax components into believing that the call succeeded when it really didn't.

    This is why I was hoping for a built-in solution - perhaps something within the Ajax framework that would catch this particular exception and display a custom error message or perform a custom redirect, so the application could at least give a meaningful error like "Sorry, this application doesn't support the back/reload buttons, please click here to go back to the original page and try your operation again."  Since r.a.d. Ajax is already handling exceptions, the ideal place to deal with that particular one is within the framework itself.

    Although it just occurred to me that the RadAjaxManager has its own redirect method - have you tried using that?

  • Giuseppe Giuseppe admin's avatar

    Posted on Nov 7, 2006 (permalink)

    Hello Richard,

    Thank you for contacting us again.

    You could use the HttpResponse.RedirectLocation property to achieve the desired functionality in your scenario.


    Greetings,
    Manuel
    the telerik team

  • kevinag avatar

    Posted on Dec 11, 2006 (permalink)

    I'm seeing the same refresh/back button issue in FireFox as described in this and other threads. Is the "global error catch and redirect" method noted above still the only way to get around this?

  • Steve Steve admin's avatar

    Posted on Dec 12, 2006 (permalink)

    Hi Kevin,

    Firefox is designed to preserve the values of the hidden fields on the page (Internet Explorer does not) and that is why it preserves the selected information when you return to the page using the Back button. We could suggest you to either check for the browser being used and set the EnableEventValidation page directive to false if it is Firefox, use the window.onunload = function()  to "clear" the selections in the dropdownlists or the suggested "refresh technique" in the forum link.

    Sincerely yours,
    Steve
    the telerik team

  • Aaron avatar

    Posted on Dec 12, 2006 (permalink)

    Something else I was wondering about recently:

    The r.a.d. Ajax controls use session state to store information that would normally be in the ViewState (or part of that information), correct?

    It's fairly easy to detect on the server-side whether or not a page is a "refresh", using the IsPostback property and a Session variable with the last page visited. (To make it really clean you need a bit more but this is just an idea here).  So...

    Would it be possible then, to decode the ViewState field (and EventTarget, EventValidation, etc.) just before rendering, apply whatever's in the Ajax session state to it, and use a JS method to overwrite those fields after Firefox has populated the expired and useless values?

    It's ugly, but it sounds plausible, and it probably would only have to be done once in the PageAdapter.  Of course I have no idea how r.a.d. Ajax uses the Session state and I haven't found that in the documentation (not sure whether that's because it's confidential or just not particularly interesting to most users).

    What do you think, could this work, and if so, would someone from Telerik be able to help at all with trying it out?

  • Giuseppe Giuseppe admin's avatar

    Posted on Dec 14, 2006 (permalink)

    Hi Aaron,

    Thank you for contacting us again.

    To tell you the truth we do not see the suggested approach (if we understand you correctly you are proposing some kind of view state decoding on the client-side) as a viable solution for this browser-specific issue. Have you seen any similar implementations around, how do they handle the scenario where view state is encrypted for security purposes for example? We would be glad if you could point us to a sample implementation that we could investigate locally and use in our considerations.


    Kind regards,
    Manuel
    the telerik team

  • Aaron avatar

    Posted on Dec 14, 2006 (permalink)

    Hi Manuel,

    If I had other examples to work with then I probably would have tried them myself. :-)

    I'm not proposing anything on the client-side, though; I guess I worded it wrong originally.  Let me try to explain further:

    The problem here seems to be that ASP.NET is emitting a value to the ViewState field (and some other hidden fields like EventTarget, EventValidation, etc.), but Firefox is replacing the contents of those fields with what it has cached.  So one way to "force" Firefox to use the "right" field values is to do it with JavaScript, which will execute after FF has made a mess of everything, and clean it up.

    The JS doesn't have to actually encode/decode anything though - the  script is generated dynamically on the server side which can access the contents of that field either through the PageAdapter or by overriding the Render method.  All the JS does is replace the contents of a few fields with literal strings generated at the server (the same strings that were supposed to be there in the first place).  In the end this would make it behave more like IE, which simply doesn't cache those hidden field values.

    I've actually tried this approach before with some limited success; that is, I verified that the contents of those fields were actually replaced with the original server-side values, but I still got some weird errors (different ones) and abandoned the approach.  But after some reflection on that, I think that could be because certain Ajax state is in the Session rather than the ViewState.  Technically an Ajax page shouldn't have any state at all when it's reloaded, but the error message (which I unfortunately don't remember the exact text of) seemed to indicate to me that it thought there was.

    If it'll help, I can rewrite the code I originally used to replace the ViewState (it was essentially just a few regexes and replaces in the Render method).  I wouldn't know if there are any "live" examples which use this however.  It could very well be that this is a dead end and that the problem exists in some other area where I haven't looked.  It just seems to me that if I can find out where all the state is, and "revert" it back to the original non-postback page state, it should eliminate this problem.

    Thanks again,
    Aaron

  • Giuseppe Giuseppe admin's avatar

    Posted on Dec 18, 2006 (permalink)

    Hello Aaron,

    Thank you for contacting us again.

    We tried a little bit different approach by overriding the SavePageStateToPersistenceMedium / LoadPageStateFromPersistenceMedium Page methods -- instead of storing the view state in a hidden field of the page we store it in the Session object. It seems this cures the corrupted view state error in Firefox but of course there is a tradeoff -- as the view state now is kept on the server-side you might experience performance drops if you are storing too large state there. I think it's up to you to choose the lesser evil for your specific project -- at least till we find a better solution. Attached is a sample application with ajaxified GridView control for your reference.

    Hope this helps.


    Regards,
    Manuel
    the telerik team

  • rcbarth avatar

    Posted on Feb 19, 2007 (permalink)

    You might try this link RE: caching of FireFox hidden fields (if this works, it's a simple two-line change to your page):

    http://erikmich.spaces.live.com/Blog/cns!EECE29F3E771C821!150.entry

  • Steve Steve admin's avatar

    Posted on Feb 20, 2007 (permalink)


    Thank you for sharing this one with the community Robert! Real slick solution:

    protected void Page_Load(object sender, EventArgs e)
    {
    if( Request.Browser.MSDomVersion.Major == 0 ) // Non IE Browser?)
    Response.Cache.SetNoStore(); // No client side cashing for non IE browsers
    }

    Best wishes,
    Steve
    the telerik team

  • Justin Wilson avatar

    Posted on Jun 9, 2007 (permalink)

    I have actually had corrupted ViewState info in IE during AJAX calls (using the RAD controls ofcourse)
    I'm currently working on a project that utilizes quite a few RAD controls. The size of our pages was crazy (300k+, we have a few tree views menus tab strips etc...) 50k of our page size was ViewState so as we worked down the page size we also tried different ways to shrink the viewState. We moved the viewState into a DB which worked perfect until we started doing AJAX calls. We would start seeing exceptions about bad viewState data. Another solution that we used was just compressing/uncompressing the viewstate (about 70% smaller).. Has anyone else had issues with storing the viewstate offline when doing AJAX calls?? 

  • Posted on Jun 18, 2007 (permalink)

    I just ran into this today and I am researching a way to get the problem rectified in FF.

    But,  I too had a problem with the viewstate in IE getting corrupt when doing refreshes.  I just disabled the viewstate on the Ajax control (ScriptManager) and it seems to fix the IE problem.

     (Your mileage may vary)

    EDIT:  I ended up using the Telerik method to store the viewstate to the session.  It fixed the problem and since I am not using the viewstate for anything by my radDock state, it shouldn't consume too much additional memory.


    Shawn

  • Amit avatar

    Posted on Feb 7, 2008 (permalink)



    i had same problem so i used hidden fields for tracking refresh [F5] from the browser.

  • Posted on Mar 17, 2009 (permalink)

    I'm having this problem too...

            Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                If Request.Browser.MSDomVersion.Major = 0 Then '// Non IE Browser?)
                    Response.Cache.SetNoStore() '; // No client side cashing for non IE browsers
                End If
    ..

    This didn't change anything for me...
    "The state information is invalid for this page and might be corrupted."

    (Also a js error, don't know if it's related:
    userAgentButton is null
    this._upperAbbrMonths = this...s.dateTimeFormat.AbbreviatedMonthNames);
    ScriptRe...200000000 (line 576
    2))





  • Iana Tsolova Iana Tsolova admin's avatar

    Posted on Mar 17, 2009 (permalink)

    Hello Robert,

    Could you please send us a sample project illustrating the issue (in a formal support ticket)? I will debug it then locally and try providing a resolution for you. 

    Looking forward your reply,
    Iana
    the telerik team

  • Piyush avatar

    Posted on Jun 19, 2009 (permalink)

    function

    onExpand(sender, eventArgs)

     {

     

    //Use sender (instance of CollapsiblePanerExtender client Behavior)
    //to get ExpandControlID.

     

     

     

    alert("Now Refresh to get new data");

     

     

     

    var expander = $get(sender.get_ExpandControlID());

     

     

     

    //var expander = $get(sender.get_TargetControlID());

     

     

     

    //Get bounds of the expand control, will be used to set position of progess indicator.

     

     

     

     

     

    var bounds = Sys.UI.DomElement.getBounds(expander); 

     

    //Progress Indicator element

     

     

     

    var progress = $get('progress');

     

     

     

    //Set Position & visibility of Pogress Indicator

     

     

     

    //Sys.UI.DomElement.setLocation(progress,bounds.x+bounds.width,bounds.y);

     

     

     

    //progress.style.visibility = 'visible';

     

     

     

    //Using RegEx to replace pnlCustomer with hdnCustId. 

     

     

     

    //hdnCustId is a hidden field located within pnlCustomer.

     

     

     

    //pnlCustomer is a Panel, and Panels are not Naming Container.

     

     

     

    //So hdnCustId will have the same ID as pnlCustomer but with

     

     

     

    //'hdnCustId' at the end insted of pnlCustomer.

     

     

     

    var mediclaimClaimId = $get(sender.get_ExpandControlID().replace(/pnlMediclaimClaim/g,'hdnMediclaimClaimId')).value;

     

     

     

    //pnlMediclaimClaimDetailCtl = $get(sender.get_ExpandControlID().replace(/pnlMediclaimClaim/g,'pnlMediclaimClaimDetail')).id;

     

     

     

    //Issue AJAX call to PageMethod, and send sender object as userContext Parameter.\

     

     

     

    var reqviaproxy = MediclaimClaimService.GetMediclaimClaimDetails(mediclaimClaimId, OnSucceeded, OnFailed);

     

     

    }
    // Callback function invoked on successful

     

     

     

    // completion of the page method.

     

     

     

    function OnSucceeded(result, userContext, methodName)

     

     

    {

    $get(

    'progress').style.visibility = 'hidden';

     

     

     

    //userContext is sent while issue AJAX call

     

     

    /

    /it is an instance of CollapsiblePanelExtender client Behavior.

     

     

    /

    /Used to get the collapsible element and sent its innerHTML

     

     

     

    //to the returned result.
    //userContext.get_element().innerHTML = result;

     

     

     

    $get(pnlMediclaimClaimDetailCtl).innerHTML = result;     //////////////        this is the problem area
                                                                      /////////////       giving the "view state corrupt" problem

     

     }
    /

    / Callback function invoked on failure

     

     

     

    // of the page method.

     

     

     

    function OnFailed(error, userContext, methodName)

     

     

    {

    $get(

    'progress').style.visibility = 'hidden';

     

    alert(error.get_message());
    }

    pls help

     

     

  • Posted on Jun 19, 2009 (permalink)

    Hi,

    just a follow up on my comment above:

    it was a firefox extension/plugin causing my error...
    Just to check if you have the same case, try to run ff with all plugins/extensions disabled and see...

  • Piyush avatar

    Posted on Jun 19, 2009 (permalink)

    i m getting the problem in IE also

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Ajax > Ajax, ViewState and Firefox