What does the "EnableViewState" property do? Why would I want it on or off?

 Posted by Rohitshah on 9/10/2008 | Category: ASP.NET Interview questions | Views: 14786
Answer:

It enables the viewstate on the page. It allows the page to save the users input on a form.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Raja on: 9/19/2008
The best answer is as follows

Enable ViewState turns on the automatic state management feature that enables server controls to re-populate their values on a round trip without requiring you to write any code. This feature is not free however, since the state of a control is passed to and from the server in a hidden form field. You should be aware of when ViewState is helping you and when it is not.

For example, if you are binding a control to data on every round trip (as in the datagrid example in tip #4), then you do not need the control to maintain it?s view state, since you will wipe out any re-populated data in any case. ViewState is enabled for all server controls by default. To disable it, set the EnableViewState property of the control to false.

Copied from: http://dev.fyicenter.com


Login to post response