Pages

ViewState Vs ControlState

we all know, in asp.net 1.x the web controls use the Viewstate to maintain state between postbacks. this involves more data to be transfered from and to the server. the best practice is to disbale ViewState when it is not required, but still this is problem in many other cases, suppose we use the DataGrid controls, which consumes most of the ViewState normally, the ViewState cannot be disabled because it has to support other events related to that control. the DataGrid page number, event command are stored in the Viewstate, so this is more inconvinient.
In Asp.Net 2.0, the Viewstate concept is changed and they have introduced the controlstate, which is a part of Viewstate, only for the purpose to maintain control state, not the content of it. Control state is another type of hidden state reserved exclusively for controls to maintain their core behavioral functionality, whereas view state only contains state to maintain the control's contents (UI). Technically, control state is stored in the same hidden field as view state (being just another leaf node at the end of the view state hierarchy), but if you disable view state on a particular control, or on an entire page, the control state is still propagated. this enables us to use more Web Controls, as the viewstate is maintained internally. this will not support DataGrid, because it is part of Asp.Net 1.x, the new controls of Asp.Net 2.0 will support this feature. even the viewstate is disabled the event triggered, other control properties are maintained in the controls state.

The supported controls are listed below.
Control -> Properties Stored in Control State
CheckBoxList -> PreviousItemCount, PreviousOffset
ContentPager -> CurrentPage, PageCount
DetailsView -> PageIndex, Mode, DefaultMode
FormView -> PageIndex, Mode, DefaultMode
GridView -> EditIndex, SelectedIndex, PageIndex, SortDirection, SortExpression
ListControl -> SelectedIndices
(base class for BulletedList, CheckBoxList, DropDownList, ListBox, and RadioButtonList)
LoginView -> TemplateIndex
MultiView -> ActiveViewIndex
Table -> CurrentRow, ViewMode

1 comment: