I'm fighting the .NET Viewstate right now and it is starting to lower me. Having discovered that some of the pages in one of our applications consist of approximately 80% of the views, I studied this when I can.
I looked through (and am pleased) disabling the viewstate for controls that it doesn't need (shortcuts, buttons, etc.), and made some small gains here.
Now I am looking at compression in the view, and although I can demonstrate a 40-50% reduction, it does not seem to work very well with my application.
Scenario: The page contains several drop-down lists, a button and a Grdiview (therefore, you must deal with ViewState!). When the page loads, DDL are populated and selected by default. Clicking OK will populate the Gridview as expected.
Now the problem: if the inclusion of ViewState Compression is enabled, if the user changes the selected elements in the DDL before clicking the “OK” button, they will receive a “Required Field Validator” error indicating that the selection was not made in one of the DDL - But this is not so ! Disabling the compression code fixes the problem and the page works as expected (i.e. for several months!).
Can the problem remain in the view, which is now stored in a key other than __VIEWSTATE [the code that I saw uses different key names - for example, VSTATE).
The stories of my page look like this:
Compressed page source (note the __VIEWSTATE empty key):
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VSTATE" id="__VSTATE" value="H4sIAAAAAEAO29B2AcSZYlJ
.
.
MKd2afqdaImFR5UiFXVyQPwLPA//8xt+pMsSQ8vlOklcoNgmZfJd8hHvk6/S/7UbxxAJTjzZfp6Qcm039
h3d3dvvPO7/Oa/7i57uemj1H2a/gw5lJQ+ySjFRtPZUL7A/3o2ImFR5UiFXVyLPA+38At70F1EkwAAA=" />
<input type="hidden" name="__VIEWSTATE" id="
__VIEWSTATE" value="" />
</div>
Page source without compression:
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTYxOTM1NDg4N
A9kFgJmD2QWAgIDD2QWAgIFD2QWAmYPZBYKAgEPZBYIAgcPZBYCAgMPDxYCHgRUZXh0BRdEYXduQyBbY2hhbm
dlIHBhc3N3b3JkXWRkAgkPFgIeB1Zpc2libGVoFgQCAQ8PFgIfAAUFQWRtaW5kZAIDDw8WAh8ABQUxNDoyNGR
.
.
.
.
.
.
kAgsPDxYEHwAFWVNlbGVjdGVkIFNlcnZpY2UgVXNlcjogPGEgY2xhc3M9J3N1U2VsZWN0b3InIGhyZWY9J2xp
c3RzZXJ2aWNldXNlcnMuYXNweCc+PGI+bm9uZTwvYj48L2E+HwFoZGQCDw8QZGQWAGQCBQ8UKwADZDwrABQEA
BYSHg9QYXJlbnRJdGVtQ2xhc3MFC2lnbW5fUGFyZW50HhdUb3BMZXZlbFBhcmVudEl0ZW1DbGFzcwUTaWdtbl
Ub3BFBhcmVudB4KSlNGaWxlTmFtZWUeFlRvcExldmVsSG92ZXJJdGVtQ2xhc3MFNGlnbW5fVG9wTGV"
/>
</div>
How does .NET know where VIEWSTATE is stored, and does it know that I moved it?
- SavePageStateToPersistenceMedium LoadPageStateFromPersistenceMedium?