Significance of turning the FORM viewstate off

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.
 
B

bruce barker

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)
 
T

Teemu Keiski

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.
 
R

Rain

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
 
J

Juan T. Llibre

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.
 
R

Rain

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top