Search code examples
asp.net.netviewstate

Page ViewState, Control ViewState and ControlState


What is the difference between Page ViewState, Control ViewState and ControlState? Why there are 3 different things in ASP.Net?


Solution

  • A Page is a Control, so inherits the ViewState property. When ViewState is saved, ASP.NET iterates over the control tree, persisting each Control's ViewState to a persistence medium (by default a hidden field in the rendered HTML).

    ViewState incurs an overhead, which can be expensive, especially for data-bound controls such as Repeater, DataGrid etc. It is therefore often desirable to disable ViewState, and instead regenerate the control on each postback.

    However in .NET 1.x this caused problems, as some controls did not work properly when ViewState was disabled - examples are paging and sorting in a DataGrid.

    ControlState was therefore introduced in .NET 2 to enable controls to save the minimal state data they need to function on postback.