views:

433

answers:

2

For some reason the viewstate of my application became gigantic (around 14 million characters). It adds around 1 minute of loading time. If the page finally loads (which is not often), the server crashes every time someone send a form because "Post size exceeded allowed limits. "

It appeared suddenly. I didn't add any fields, just some javascript on the page.

People told me to check viewstate chunking out. Google told me to do this:

<pages maxPageStateFieldLength="1024">

... so now instead of a huge hidden field I now have something like 100 very large hidden fields. It's not exactly what I was looking for.

Why would .NET do something like this? How can I fix this?

+2  A: 

Keep in mind that controls will retain their values across postbacks without viewstate. You can often disable viewstate for a lot of your controls without any issues. To disable viewstate for a specific control set:

EnableViewState="false"

If you set this for all of your grids and any controls that you don't need viewsate for it will significantly reduce the size.

Chris Pebble
I did this and it didn't change anything. I'm including .ascx files like this: <uc1:attributeAutocomplete EnableViewState="false" runat="server" id="_temposAutocomplete" ></uc1:attributeAutocomplete> and there's quite a lot of JS going on in there. Could it be linked? I disabled the viewstate for these and it didn't fix it
marcgg
I figured it out (see accepted answer)! I accepted beska's because it's the answer that helped me figure out the issue, but yours was also helpful... so +1 and thank you very much :) !
marcgg
+2  A: 

I would suggest using a utility to decode your viewstate so you can get an idea of what is actually within it (since you obviously have a lot of information in there you don't seem to need.)

A utility like Fritz Onion's viewstate decoder should allow you to see what's in your viewstate that you aren't expecting. Then you can either modify your code, remove the offending control, or selectively disable viewstate for the controls that shouldn't have it enabled.

Beska
Thanks, it looks pretty cool, I'll test this right now
marcgg
That's annoying, the software crashes, apparently the string is too large. But now I know that my viewstate is 13 428 604 characters long :)
marcgg
It finally run without crashing on my 5th attempt :) It looks like it's putting all my page in the viewstate... it's quite weird. I'll try to see what's the logic here and come back on SO
marcgg
Ok I figured it out. I accept your answer because you're the one that lead me in the right direction... even thought Chris' answer also helped me a lot. The problem was that this page was a search page... and for some reason it included all the results in the viewstate even though there was no search done. I saw that using the viewstate decoder. Then fixing it was simple, I added EnableViewState="false" on the .ascx that kept the search results and it fixed it. yay!
marcgg
@marcgg That was what I ment by turning off the viewstate :) Glad you figured it out.
Mikael Svenson