System.Web.UI Namespace Control Class
Sets or retrieves a value indicating whether the server control persists its view state to the requesting client.
Inline |
<asp:control EnableViewState = true | false ... > |
Script |
Control.EnableViewState [ = true | false ] |
This property accepts or returns only a boolean value: true if the server control maintains its view state; otherwise false.
This property is read/write with a default value of true.
You must enable view state for the server control to maintain its state across HTTP requests.
A server control's view state, and the view state of any child controls it contains, is the accumulation of all its property values. In order to preserve these values across HTTP requests, ASP.NET uses an instance of the StateBag class to store the property values. The values are then passed as a variable to a hidden field when subsequent requests are processed. For more information about view state, see Web Forms State Management.
There are times when it is appropriate to disable view state, particularly to improve application performance. For example, if you are loading a database request into a server control, set this property to false. If you do not, processor time will be wasted loading view state into the server control that will only be overridden by the database query.
For information about how to enable or disable view state declaratively for an ASP.NET page, see the @ Page directive.
The following example demonstrates setting the EnableViewState property to false.
<asp:datagrid id="myGrid" runat="server"
width="95%"
cellpadding=3
font-size="8pt"
headerstyle-backcolor="#bbccdd"
headerstyle-font-bold
enableviewstate=false />
Show me
Control Members Web Forms Page Processing Stages Web Forms State Management | @ Page