IsPostBack Property
TOC
Collapse the table of content
Expand the table of content

Page.IsPostBack Property

 

Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

[BrowsableAttribute(false)]
public bool IsPostBack { get; }

Property Value

Type: System.Boolean

true if the page is being loaded in response to a client postback; otherwise, false.

For an explanation of the difference between postbacks and callbacks, see Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages.

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 to be displayed immediately when the page is rendered, instead of waiting until the user clicks the Submit button. After a postback, you do not have to call Page.Validate, because that method is called as part of the Page life cycle.

private void Page_Load()
{
    if (!IsPostBack)
    {
        // Validate initially to force asterisks
        // to appear before the first roundtrip.
        Validate();
    }
}

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft