
Test Page for the IndexButton Control
The following example illustrates a page that disables view state by setting the EnableViewState attribute to false in the @ Page directive. The page uses the IndexButton control and adds 1 to the values of the Index and IndexInViewState properties of the control in the Page_Load event handler. The labels in the page display the values of the Index and IndexInViewState properties.
Because the Index property is stored in control state, which cannot be disabled, the Index property maintains its value on postback and increases by one each time the page is posted back to the server. In contrast, because the IndexInViewState property is stored in view state, which is disabled for the page, the IndexInViewState property always has its default value of zero.
<%@ Page Language="VB" Trace="true" EnableViewState="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = IndexButton1.Index.ToString()
Label2.Text = IndexButton1.IndexInViewState.ToString()
IndexButton1.Index += 1
IndexButton1.IndexInViewState += 1
End Sub
</script>
<html >
<head id="Head1" runat="server">
<title>IndexButton test page</title>
</head>
<body>
<form id="form1" runat="server">
Click the button:
<aspSample:IndexButton Text="IndexButton"
ID="IndexButton1" runat="server"/>
<br />
<br />
The value of the Index property of IndexButton is:<br />
<asp:Label ID="Label1" Runat="server" Text="Label">
</asp:Label>
<br />
<br />
The value of the IndexInViewState property of IndexButton is:
<br />
<asp:Label ID="Label2" Runat="server" Text="Label">
</asp:Label>
<br />
</form>
</body>
</html>
<%@ Page Language="C#" Trace="true" EnableViewState="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
Label1.Text = (IndexButton1.Index++).ToString();
Label2.Text = (IndexButton1.IndexInViewState++).ToString();
}
</script>
<html >
<head id="Head1" runat="server">
<title>IndexButton test page</title>
</head>
<body>
<form id="form1" runat="server">
Click the button:
<aspSample:IndexButton Text="IndexButton"
ID="IndexButton1" runat="server"/>
<br />
<br />
The value of the Index property of IndexButton is:<br />
<asp:Label ID="Label1" Runat="server" Text="Label">
</asp:Label>
<br />
<br />
The value of the IndexInViewState property of IndexButton is:
<br />
<asp:Label ID="Label2" Runat="server" Text="Label">
</asp:Label>
<br />
</form>
</body>
</html>