Sdílet prostřednictvím


SYSK 354: How To Determine If The Page_Load Event Is Triggered by a Standard Page Postback or by the UpdatePanel?

Ok, so you’re in a Page_Load code block, and the this.Page.IsPostBack returns true. How do you know if the request is due to a “standard” page postback or as a result of an UpdatePanel triggered postback resulting in a partial page update?

 

The answer is simple: when the postback is caused by a trigger for the UpdatePanel control or when you explicitly call the UpdatePanel control's Update() method, the this.ScriptManager1.IsInAsyncPostBack property will return true; whereas during a “normal” postback that value will be false.

 

Note: in both cases the this.Page.IsAsync will be false.

Comments

  • Anonymous
    July 12, 2007
    Ok, so you’re in a Page_Load code block, and the this.Page.IsPostBack returns true . How do you know

  • Anonymous
    July 12, 2007
    This is a great tip, but how do you find that out from a UserControl when you're using a ScriptManagerProxy?

  • Anonymous
    April 13, 2008
    Here is how to do it in UserControl even if you are using ScriptManagerProxy:    protected void Page_Load(object sender, EventArgs e)    {        if (Page.IsPostBack)        {            // get a reference to ScriptManager and check if we have a partial postback            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)            {                // partial (asynchronous) postback occured            }            else            {                // regular full page postback occured            }        }    } hope it helps...

  • Anonymous
    January 13, 2009
    Thank you, this is very helpful.