Name
IsPostBack
Synopsis
Boolean = Page.IsPostBack
Returns
a Boolean
value that indicates if the page is loaded for the first time
(False) or is loaded as a result of the client
postback (True). This property comes handy for the
logic that needs to be executed the first time the page is executed
or every time the page is posted back to itself, depending on how you
structure your If statement.
Parameters
-
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 code example below 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 ...
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