asp.net.ph

Page.IsPostBack Property

System.Web.UI Namespace   Page Class


Returns 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.

Syntax


Script [ bool variable = ] Page.IsPostBack

Property Value

This property returns only a boolean value: true if the page is being loaded in response to a client postback; otherwise, false. Default value is false.

Remarks

Use the IsPostBack property to test either of two states:

  1. if the page is being loaded and accessed for the first time ( IsPostBack returns false ), or
  2. if the page is being loaded in response to a client postback ( IsPostBack returns true ).

This property is typically used within a Page_Load event handler to conditionally execute one or more embedded statements, depending on the IsPostBack state when the page is loaded.

Example

The following example evaluates IsPostBack on page load, and runs the embedded statements only if IsPostBack is not true, indicating the page is being accessed for the first time.

protected void Page_Load ( Object Src, EventArgs E ) {
   if ( !IsPostBack ) {
      string query = "SELECT DISTINCT Type FROM Products";
      mySelect.DataSource = fetchData ( query, "gear" );
      mySelect.DataBind ( );
   }
}

 Show me 

See Also

Page Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph