View State Improvements in ASP.NET 2.0 State/default.aspx

What is the View State?

The view state is a hidden form variable containing data encoded in base-64 to represent the state of server side controls on an ASP.NET page.

What’s wrong with the View State?

The view state can become large on pages that include a large number of controls, or complex controls like the DataGrid, that retain state. The view state is embedded in web pages posted to the browser. A large view state could significantly affect the responsiveness of an ASP.NET page if a large view state is downloaded and reposted for each round-trip.

Can the View State be turned off?

Yes, and in cases where no state is required, turning off state at the control level can reduce the size of the view state. However, some controls, such as the DataGrid control, use state to manage the operation of the control as well as the data associated with it. For example the DataGrid control uses the view state to control pagination.

Disabling the view state for some controls may affect post-back events. Text boxes and drop-down lists rely on the view state to determine if the content of the control has changed before firing a changed event.

Improvements in ASP.NET 2:

Serialization – The view state is binary serialized data, generated by each control retaining state, which is then encoded in base-64. ASP.NET 1.x used a number of less-than and greater-than characters to define field separation. ASP.NET 2 now uses single binary control characters, and requires fewer to encode the state of a control.

Base-64 adds a 30% overhead to serialized data.

Control State – The view state is now partitioned into two separate categories: control state and view state. The control state manages core behavioral functionality, whereas the view state is now only used to manage the controls content (UI). The control state is stored alongside the view state as base-64 in the hidden field, as before, only disabling the view state for a control will only disable the content management portion, retaining the control state for correct control behavior.