Updated: April 2009
Gets a value indicating whether the page is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.
<BrowsableAttribute(False)> _ Public ReadOnly Property IsPostBack As Boolean
Dim instance As Page Dim value As Boolean value = instance.IsPostBack
[BrowsableAttribute(false)] public bool IsPostBack { get; }
[BrowsableAttribute(false)] public: property bool IsPostBack { bool get (); }
public function get IsPostBack () : boolean
The following example shows how to test the value of the IsPostBack property when the page is loaded in order to determine whether the page is being rendered for the first time or is responding to a postback. If the page is being rendered for the first time, the code calls the Page..::.Validate method.
The page markup (not shown) contains RequiredFieldValidator controls that display asterisks if no entry is made for a required input field. Calling Page..::.Validate causes the asterisks as to be displayed immediately when the page is rendered, instead of waiting until the user clicks the Submit button. After a postback, it is not required to call Page..::.Validate, because that is part of the ordinary Page life cycle.
Sub Page_Load If Not IsPostBack ' Validate initially to force the asterisks ' to appear before the first roundtrip. Validate() End If End Sub
private void Page_Load() { if (!IsPostBack) { // Validate initially to force asterisks // to appear before the first roundtrip. Validate(); } }
function Page_Load() { if (!IsPostBack) { // Validate initially to force the asterisks // to appear before the first roundtrip. Validate(); } }
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
Date
History
Reason
April 2009
Added text to explain the code example.
Customer feedback.