This documentation is archived and is not being maintained.

Control.EnableViewState Property

Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client.

[Visual Basic]
Public Overridable Property EnableViewState As Boolean
public virtual bool EnableViewState {get; set;}
public: __property virtual bool get_EnableViewState();
public: __property virtual void set_EnableViewState(bool);
public function get EnableViewState() : Boolean;
public function set EnableViewState(Boolean);

Property Value

true if the server control maintains its view state; otherwise false. The default is true.


You must enable view state for the server control to maintain its state across HTTP requests.

A server control's view state 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 Introduction to 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 @ Page.


[Visual Basic, C#] The following example sets the EnableViewState property to false.

[Visual Basic] 
Sub Page_Load(sender As Object, e As System.EventArgs)
   ' Set EnableViewState to false to disable saving of view state 
   ' information.
   myControl.EnableViewState = False
   If Not IsPostBack Then
      display.Enabled = False
   End If 
End Sub

void Page_Load(object sender, System.EventArgs e)
      // Set EnableViewState to false to disable saving of view state 
      // information.
      myControl.EnableViewState = false;
      if (!IsPostBack)
         display.Enabled = false;

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | ViewState | LoadViewState | SaveViewState | @ Page | Web Forms Page Processing | Maintaining State in a Control | Introduction to Web Forms State Management