ViewState Enhancements in ASP.NET 4.0
In ASP.NET, you use ViewState to preserve data across postbacks. You can specify or use ViewState at the page level and at the control levels. Although ViewState is great at preserving data after a roundtrip, it adds significant overhead in terms of the rendered page size and also performance. Note that though ViewState is optional in ASP.NET, it is enabled by default. One major issue in the earlier version of ASP.NET was that if ViewState for a page was enabled, then the ViewState for any server control in that control would be preserved. In essence, you didn't have any choice on enabling or disabling ViewState for child controls or contained (server controls contained in a page) controls.
ASP.NET 4 introduces a new property called ViewStateMode, which you can use to specify ViewState for a particular control in your page even if ViewState is disabled for the page in which the control is contained.
Essentially, this property allows you to specify whether ViewState would be enabled, disabled, or inherited for a particular control:
- Enabled — This is used to enable ViewState for a particular control and its child controls
- Disabled — This is used to disable ViewState for a particular control
- Inherit — This is used to indicate that a particular child control will inherit the ViewStateMode property of its parent control