Have you ever developed a web application with several Ajax Update panels on one page and then wondering which one caused the postback ?
Well, this happened to me and after many dead ends, here is the key to finding what UpdatePanel caused the Post:
<br />
ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID<br />
This returns the actual element ID that forced the Post. How does this help? Well, any post that originated in a UpdatePanel would be from a child control. So, if you walk up the control tree and find a UpdatePanel, you will have the UpdatePanel that caused the Post.
private UpdatePanel GetUpdatePanelThatCausedPostback()
{
var c = Page.FindControl(ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID);
while (c != null && !(c is UpdatePanel)) { c = c.Parent; }
if (c != null) return (c as UpdatePanel);
else return null;
}
Here we get the control that actually fired the Post and then we walk up the control tree, one by one, until we are either past the top (null) or we have found an UpdatePanel.
Then we simply either return the newly found UpdatePaenl or we return null.