VIEWSTATE?

This is an open forum for any mojoPortal topics that don't fall into the other categories.

This thread is closed to new posts. You must sign in to post in the forums.
1/16/2009 12:13:08 AM
Gravatar
Total Posts 41

VIEWSTATE?

 

What is Viewstate?  Why is it sometimes in my generated home page I get a couple of these lines

input type="hidden" name="__VIEWSTATE1" id="__VIEWSTATE1" value="FgQe......

and sometimes I get 70 of them... VIEWSTATE1, VIEWSTATE2, VIEWSTATE3....?

Thanks
Rob

1/16/2009 1:43:14 AM
Gravatar
Total Posts 55

Re: VIEWSTATE?

Viewstate is ASP.NET mechanism by which it remembers state of user interface elements in the page after submiting page back to server. For example, if you have textbox on page and write some text into it and then click some Save or similar button, textbox's value is written into that textbox's viewstate. Another phrase for page submit (form submit, to be more precise), more common among users of Microsoft web technologies, is "postback". Basically, it happens whenever you click some button (or linkbutton) on web page.

In the days of classic ASP (without .NET suffix) there was no viewstate mechanism so developers had to manually keep track of user interface elements state.

Excellent article for laymen about viewstate is here: http://www.aspnetresources.com/articles/ViewState.aspx

 

1/16/2009 7:05:35 AM
Gravatar
Total Posts 18439

Re: VIEWSTATE?

In addition to the good information Slaven has provided, I can say that one of the problems with viewstate currently is that if anything on the page needs it enabled it has to be enabled for the whole page, though you can disable it on individual controls if you know thay don't need it. This is going to be improved when 4.0 .NET ships, it will be possible to turn it off at the page and turn it on case by case on controls as needed which is the opposite of the way it is now and will be much better.

A good while back, like before MS AJAX, I had things optimised in mojoPortal by turning it off at the page on the main content system page Default.aspx, but as more and more features begin to use ajax it was pretty much always needed so it is now enabled by default. If you have events you need to respond to on grids, repeaters, calendars, then you have to enable viewstate for those events to work. Some of the fancier widgets like calendar produce a lot of viewstate. Typically you will see more viewstate in edit pages that have bound controls that need to postback.

Some pages could be optimised further to reduce viewstate by going through and setting EnabledViewSate="false" on controls that don't need it. I've already done this on some pages where I've noticed very large viewstate, but there are probaly more places it could be reduced a little with this technique. Even labels and literals produce viewstate if its not disabled on the control and is enabled on the page, so adding EnableViewState="false" on those is a good idea. Again, though, when 4.0 .NET comes out this won't be needed.

Another thing to know is that by default the viewstate would all be in one hidden field not broken up as it is in mojoPortal. We break it up by enabling ViewState chunking from web.config, on the <pages element in the system.web section you will see maxPageStateFieldLength="100" which sets the max length for any viewstate field and causes it to be brooken up into hidden fields not bigger than that. Though doing this actually increases the total amount of viewstate size because the additional hidden fields produce a little more markup each. The reason to use viewstate chunking is because some firewalls seem to think a page with huge hidden fields must be malicious content and also because some mobile devices have limits on the size of hidden fields.

Best,

Joe

1/16/2009 12:09:45 PM
Gravatar
Total Posts 41

Re: VIEWSTATE?

Wow. Thanks guys. I wasn't expecting such and in depth answer. Looks like I've got a lot to learn. So many projects so little time.

 

You must sign in to post in the forums. This thread is closed to new posts.