Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewstate hidden field so big it makes everything crash

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?

like image 355
marcgg Avatar asked Aug 24 '09 17:08

marcgg


2 Answers

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 viewstate decoder will 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 (using the EnableViewState="false" attribute) for the controls that shouldn't have it enabled.

like image 195
Beska Avatar answered Nov 14 '22 22:11

Beska


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.

like image 21
Chris Van Opstal Avatar answered Nov 14 '22 23:11

Chris Van Opstal