Sep 11, 2012

View State vs Control State


Control State is another state management technique which is essentially a private view state for your control.

In order to preserve the page and control data over round trips to the web server, traditionally we are using View State. View State Property maintains information in hidden field and the data is encrypted.


If you disable the View State in your page, the custom controls which used in your page has a chance of losing their state.


To Address the above issue ASP.NET 2.0 has introduced Control State  which is private View State for the control and preserves the state of the control even when you turn off the View State.


Use the Control State property when you are developing the Custom Control by overriding the SaveControlState method to save the data in Control State.


Note that Control State Can not be disabled.



Control State (or ControlState) was introduced with ASP.NET 2.0 as an alternative to View State (or ViewState) as a method for preserving the state of a control.
Control State is designed only to  store a control’s essential data (like a dropdown list’s selected item) that needs to be available on a page postback. Unlike View State, Control State cannot be disabled.  to enable the control to function even when view state has been disabled. ASP.NET   stores the control state in for pages in the same hidden element which stores the view state. So if all you wish to do is preserve the control’s basic state over postbacks you can disable View State and Control State will handle all the preserving of state and reduce the page load.

No comments:

Post a Comment