Name
EnableViewState
Synopsis
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.
Parameters
-
Boolean A Boolean value that indicates whether the page maintains its view state.
Example
The following code example sets EnableViewState to
False using the EnableViewState
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" name="_ _VIEWSTATE"
value="dDwxMDA3MzE2MzEyOzs+" />If the EnableViewState property is set to True,
the source will look similar to:
<input type="hidden" name="_ _VIEWSTATE" value="dDwxMDA3MzE2MzEyO3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDM+Oz47bDx0PHA8cDxsPF ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access