This took me a little longer to figure out than I thought it was....it didn't help that there was a power outage in the middle of trying to answer the question either...
My original response was that the PageRequestManager is used for all UpdatePanels and that there isn't a way to determine which one caused the postback.
I decided to look into this and discovered that there is a way to figure it out but it's not documented.
Here's what I did:
- Added 2 UpdatePanels to the page
- Added 1 button to each UpdatePanel
- Implemented a method to handle the end request event
- Looked at the properties and methods of the Objects passed as parameters to the method to see if you can determine which UpdatePanel caused the postback
- Tested in normal page and tested in a page that uses a MasterPage
This is the code I used. I also used FireFox's FireBug tool to look at the JavaScript Objects, but I could have used IE8's debugging tool just as easily:
-
<script type="text/javascript">
-
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
-
//Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
-
-
function endRequestHandler(sender, args) {
-
var postbackSettings = sender._postBackSettings.panelID;
-
alert(postbackSettings);
-
}
-
//function pageLoadedHandler(sender, args) {
-
// var updatedPanels = args.get_panelsUpdated();
-
// for (i = 0; i < updatedPanels.length; i++) {
-
// alert(updatedPanels[i].id);
-
// }
-
-
//}
-
-
</script>
-
<asp:UpdatePanel ID="Update1" runat="server">
-
<ContentTemplate>
-
<asp:Button ID="buttonInUpdate1" runat="server" Text="Button In Update1" />
-
</ContentTemplate>
-
</asp:UpdatePanel>
-
<asp:UpdatePanel ID="Update2" runat="server">
-
<ContentTemplate>
-
<asp:Button ID="buttonInUpdate2" runat="server" Text="Button In Update2" />
-
</ContentTemplate>
-
</asp:UpdatePanel>
-
There are 2 parameters that are passed to the JavaScript method that handles the endRequest event: the sender, and the args.
The sender object contains a property:
_postBackSettings. This property contains an object that has a couple of other properties but the one you're interested in is the
panelID property. This property has the name of the UpdatePanel and the control that caused the postback delimited by a "|".
You should be able to retrieve the UpdatePanel ID from this (by using regular expressions or the String.Split() method).
I tested it in a normal page and in a page that uses a MasterPage. Both cases correctly returned the clientID of the UpdatePanel.
Cheers!
-Frinny