Question

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

Was it helpful?

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.

OTHER TIPS

  • View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips. When the HTML markup for the page is rendered, the current state of the page and values that must be retained during postback are serialized into base64-encoded strings. This information is then put into the view state hidden field or fields.

Link 1

Link 2

  • Control state, introduced in ASP.NET version 2.0, is similar to view state but functionally independent of view state. A page developer can disable view state for the page or for an individual control for performance. However, control state cannot be disabled. Control state is designed for storing a control's essential data (such as a pager control's page number) that must be available on postback to enable the control to function even when view state has been disabled.

Link 1

  • Control ViewState Gets a dictionary of state information that allows you to save and restore the view state of a server control across multiple requests for the same page.

Link 1

Hope this helps somewhat

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top