Tuesday 17 January 2012

IsPostBack in Asp.net

What is isPostback property?


This property is used to check whether the page is being loaded and accessed for the first time or whether the page is loaded in response to the client postback. 
"Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback."

Example:
Consider two combo boxes
In one lets have a list of countries
In the other, the states.
Upon selection of the first, the subsequent one should be populated in accordance. So this requires postback property in combo boxes to be true.

In code Behind in c#.net

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

No comments:

Post a Comment