How to check whether UpdatePanel is posting back?

Sunday Ironfoot picture Sunday Ironfoot · Nov 18, 2011 · Viewed 11.1k times · Source

Is there a way to determine if an <asp:UpdatePanel /> has performed an Ajax postback similar to how we can use...

if(!Page.IsPostBack) { ...snip }

... to determine if a postback from a button submit is taking place.

I'm trying to detect Ajax requests from jQuery, but it's picking up UpdatePanel requests as well which I want to exclude eg...

if (Request.IsAjaxRequest() && !Page.IsUpdatePanelPostback)
{
    // Deal with jQuery Ajax
}

Answer

kay.herzam picture kay.herzam · Nov 18, 2011

You can check whether the postback was asynchronous and whether it was issued by an update panel looking at these properties:

ScriptManager.GetCurrent(Page).IsInAsyncPostback
ScriptManager.GetCurrent(Page).AsyncPostbackSourceElementID