
250
|
Chapter 12: The Page Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
EnableViewState
Boolean = Page.EnableViewState
Page.EnableViewState = Boolean
Returns or sets a Boolean value that indicates whether the Page maintains its view
state and that of server controls it contains. The default value of this property is
True, which means that the page maintains its view state.
Parameter
Boolean
A Boolean value that indicates whether the page maintains its view state.
Example
The following code example sets EnableViewState to False using the Enable-
ViewState
attribute of the @ Page directive and displays its value on the page:
<%@ Page Language="vb" EnableViewState="True" %>
<html>
<head>
<title></title>
<script runat="server">
Sub Page_Load( )
If Page.EnableViewState = True Then
Message.Text = "ViewState is enabled."
Else
Message.Text = "ViewState is disabled."
End If
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:label id="Message" runat="server"/>
</form>
</body>
</html>
Notes
The EnableViewState property can also be specified using the EnableViewState
attribute of the @ Page directive, as shown in the example.
Examining a page’s HTML source using a browser’s View Source feature shows
the effect of the EnableViewState property. If the EnableViewState property is set
to False, the source will look similar to:
<input type="hidden" ...