Reputation: 1873
The state information is invalid for this page and might be corrupted
This seems to be a pretty common question. But I have not yet found a post where the basic issue is addressed.
I have a heavily ajaxed application and I am running into this. In a nutshell, the ASPX page is litle more than a series of divs that are populated w/ HTML by AJAX calls. If anyone has comments on these basic questions I would greatly appreciate it. I will begin a sample app and see if I can answer them as well.
runat=server
controls w/ Ajax cause this. runat=server
control , will that trigger this. runat=server
control before returning it as part of an ajax ctl.( For example - a repeater is really nice to build a table. Can i use the repeater and then remove some syntax from the HTML before I send the response to the client. I can do the looping if i have to.. )
4) Is there something I can put in the header to make this whole thing go away.
Page Language="vb"
AutoEventWireup="false"
CodeBehind="frustration.aspx.vb"
_Inherits="Portal.frustration"
EnableViewState="false"
enableViewStateMAC="false"
EnableEventValidation="false"
ValidateRequest="false"
ViewStateEncryptionMode="Never"
MasterPageFile="~/_MasterPages/Admin.Master"
Thanks, greg.
Upvotes: 1
Views: 1007
Reputation: 1873
Well, I got it to work, but I'm abandoning the .NET menu anyway. Since I was looking for some high level information, I will let the community what I was able to do...
The viewstate issue happens when I load the AJAX page then navigate using the menu. It happens because clicking the menu posts back to my AJAX page before it navigates away. If it were just a hyperlink, there would be no issue.
The AJAX page in question is essentially 3 divs. Div_A is a navigation element consisting of a list of documents. Div_B is a read only detail of 1 document w/ some action buttons. Div_C is an input form. The divs are populated by jQUery ajax calls. On success, I replace the entire innerHTML of the DIV in question. Div_A & Div_B are automatically populated at page load in that order. (List and first document detail)
Breaking things down, just populating Div_A caused the problem. Inspection showed that I had some DIVs w/ RUNAT=SERVER. I removed that. This did not resolve the problem. There was also a FORM around the entire content. The form was tagged runat=server. I removed the FORM completely. This allowed me to use the menu without the viewstate error. However, If i clicked a second document, causing Div_B to reload. The problem reoccurred.
Div_B had the same FORM surrounding everything. (These must have be placed automatically by Visual Studio. There is no reason to have either form as both DIV_A and DIV_B are readonly) The interesting thing about DIV_B is that there are DIVs with RUNAT=SERVER that I need because I set the innerText in the code behind. Removing the FORM allowed me to navigate between documents and still be able to use the menu without VIEWSTATE errors.
So : Having RUNAT=SERVER HTML elements added to a page DOES NOT seem to break VIEWSTATE Having a RUNAT=SERVER FORM added to a page DOES seem to break VIEWSTATE.
So things are back to working, but why did this problem crop up suddenly? Not sure. Much has changed and I can't point to any 1 thing. (Maybe the FORMs got autogenerated when I upgraded from vs10->vs12). Who knows, who cares...
Ultimately - I can't continue to coddle this problem just for the sake of the .NET menu item. To @Brad M's point, I have decided to just use a jQuery menu and that will eliminate any wholesale page postbacks to this page.
A little searching and I uncovered arnab_bandyopadhyays' implementation of a horizontal jQuery menu which he demonstrates here: http://jsfiddle.net/yRJ9g/.
<<stackoverflow wants some code if i reference jsfiddle, so here ya go...>>
dim viewStateWorksWellWAjax as boolean =false
Thanks for the suggestions.
Greg
Upvotes: 1