Significance of turning the FORM viewstate off

  • Thread starter Thread starter Rain
  • Start date Start date
R

Rain

Hi,

I noticed the other day when I was trying to optimise the traffic on a
particular web page that it had significant viewstate even though I had
turned it off for most of the controls. So in a bold step I decided to
attempt to set viewstate on the form itself off which had a massive impact
on the viewstate like 80K to 15k.

So my question is what is the significance of turning off the viewstate for
the form and what information does it hold which would have made such a
drastic reduction.


Thanks.
 
every control stores all of its property values in viewstate, so that on
postback, your code does not have to set them to the rendered values. 99% of
the properties are set in the aspx page itself and never change, so saving
them in viewstate is a waste.

except for internal websites (local lan), you should always turn viewstate
off at the page level, and reset any modified value in the oninit of the
postback (normally you'd save these values in session).

-- bruce (sqlwork.com)
 
To add to what Bruce already said. Some controls utilize also control state
(control authors decide if they use it) which cannot be turned off by the
page developer. Control state should be used only for critical stuff which is
required for the control to work correctly. Why I'm saying this is that
control state is also roundtripped in a hidden field like viewstate is.

But effectively: optimizing viewstate should always be done. You already saw
it yourself how much it can have impact.
 
Thank you for your answer Bruce.

If I turn it off at the page level. Can I then explicitly turn it on control
by control ?

Thanks
 
re:
!> If I turn it off at the page level. Can I then explicitly turn it on control by control ?

If you turn it off for the page, no controls on the page will be able to
access that page's viewstate...because viewstate won't exist for that page.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
OK,

Thank you for that Julian.




Juan T. Llibre said:
re:
!> If I turn it off at the page level. Can I then explicitly turn it on
control by control ?

If you turn it off for the page, no controls on the page will be able to
access that page's viewstate...because viewstate won't exist for that
page.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Back
Top