Difference between ViewState and ControlState:

 Posted by Ddd on 1/22/2011 | Category: ASP.NET Interview questions | Views: 31831 | Points: 40

ViewState and ControlState are both mechanisms used in ASP.NET for maintaining data across postbacks. Both are preserved in a hidden field known as _VIEWSTATE.
The differences are:
1)ViewState can be disabled while the Control State cannot be disabled.
2)ViewState is implemented by using EnableViewState property of a control to true.
Control State works even when EnableViewState is off.

To use Control State (for example in a custom control) we have to override OnInit method,call RegisterRequiresControlState method in OnInit method and then override the SaveControlState and LoadControlState methods.

Custom Controls code is written in classes derived from WebControl.

3)Control State is used for small data only.
eg: maintain clicked page number in a GridView even when EnableViewState is off

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response