As I understand it, partial page updates with ASP.NET AJAX cause the JavaScript pageLoad() event handler to be invoked.
My question: Is there a generic way of determ
To determine if the postback was a partial update or not, you can use ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack
. Here's an example:
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
// insert Ajax custom logic here
}
else
{
// regular full page postback occured
// custom logic accordingly
}
}
}
And to get the Update Panel that caused the PostBack, you can look into ScriptManager.GetCurrent(Page).UniqueID
and analyze it. Here's an example of doing that:
public string GetAsyncPostBackControlID()
{
string smUniqueId = ScriptManager.GetCurrent(Page).UniqueID;
string smFieldValue = Request.Form[smUniqueId];
if (!String.IsNullOrEmpty(smFieldValue) && smFieldValue.Contains("|"))
{
return smFieldValue.Split('|')[0];
}
return String.Empty;
}
References: