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 determining in JavaScript from within the pageLoad() function...
i) If the postback was a partial page update or not.
ii) If so, which panel was updated.
My application uses a combination of .NET UpdatePanels & Telerik RadAjaxPanels. I'm looking for a generic (preferably JavaScript) solution which doesn't require me to specify a unique client-side callback function for each panel, nor set some flag from within each postback event handler to identify itself to the client-side.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With