Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
difference between control and page view state? if page view state if False then Control view state Work or Not?Can child control view state also work or Not?
Posted

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

For more info : Using Control State in ASP.NET 2.0[^]

Control State vs. View State
 
Share this answer
 
v3
 
Share this answer
 
v2
Comments
That is MSDN not msn bro. :P :) Please correct.
joginder-banger 15-Dec-13 12:07pm    
thanks sir
Most welcome. :)
For the both of your questions, the answer is NO. if the EnableViewState of parent page is set false then the ViewState for all the controls on the page will not work. same for parent and child controls.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900