Translate

Sunday 7 December 2014

ASP.NET Control State vs View State

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.

The ControlState is ALWAYS sent to the client on the viewstate field no matter if you have enabled ViewState or not.

So you can expect to drastically reduce the size of the viewstate field sent to the client but not completely remove it.

Control state are the minimal things that a control need to persist across postbacks in order to work as expected.

Control State

In addition to view state, ASP.NET supports control state. The page uses control state to persist control information that must be retained between postbacks, even if view state is disabled for the page or for a control. Like view state, control state is stored in one or more hidden fields.

--------------

Control State is similar to View State except that it is used to preserve only critical state information. For example, the GridView control uses Control State to store the selected row. Even if you disable View State, the GridView control remembers whichrow is selected.