
252
|
Chapter 12: The Page Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
or every time the page is posted back to itself, depending on how you structure
your
If statement.
Parameter
Boolean
A Boolean value that indicates if the page is loaded for the first time or is
loaded as a result of the client postback.
Example
The next code example uses the IsPostBack property to display different messages
in the Label control, depending on whether the page is loaded for the first time or
is loaded as a result of the client postback. The first time the page is loaded, the
IsPostBack property returns
False, causing the string “Non-PostBack” to be
displayed. Clicking the button posts the page back to itself, causing IsPostBack to
return
True and the string “PostBack” to be displayed.
<%@ Page Language="vb" %>
<html>
<head>
<title></title>
<script runat="server">
Sub Page_Load( )
If Page.IsPostBack Then
Message.Text = "PostBack"
Else
Message.Text = "Non-PostBack"
End If
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:button id="post" Text="Post page" runat="server"/>
<asp:label id="Message" runat="server"/>
</form>
</body>
</html>
Notes
The IsPostBack property will return True only for pages that contain a <form>
element with the runat="server" attribute and at least one control that causes a
postback. This can be a Button control,