Multiple UpdatePanels - Who caused the update ?

by JoeStagner 4/19/2008 10:50:00 AM

Does your client code need to know what control caused your update panels to update or which of several UpdatePanels contained the triggering control ? Try this.... (Or do the same thing with addbeginRequest();

    1 <script type="text/javascript">
    2 <!--
    3 var prm = Sys.WebForms.PageRequestManager.getInstance();
    4 
    5 prm.add_endRequest(EndRequest);
    7 function EndRequest(sender,args)
    8     {
    9     alert(sender._postBackSettings.panelID + " -> " + sender._postBackSettings.sourceElement.id);
   10     }
   11  -->
   12 </script>


 Note that "id" contains the id of the CONTROL that caused the postback. panelId contains a string that appends the event trigger with the UpdatePanel name.   Note that if the update was caused by an event configured in the Triggers Collection or updated explicitly in JavaScript, the "Control" name will be the UpdatePanel.

Currently rated 4.0 by 8 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

AJAX | ASP.NET | Joe Stagner [Syndicated]

Related posts

Comments

4/20/2008 2:51:02 AM

Hi Joe,
I have two update panels which has a trigger outside those update panels. How do I get the Update panel ids which caused the async postback in the begin request?

shane au

4/20/2008 5:12:03 AM

hi
there is a control with some features like disabling the element which caused the call back and so on named postbackritalin at encosia.com

Mojtaba Vali ir

4/20/2008 2:41:40 PM

Thanks.

victorantos ro

4/21/2008 4:19:38 AM

The only problem persay with this approach is that it doesn't work for programatically created, nested update panels - it always returns the name of the update panel at the top level - very frustrating!

I've had to essentially do the work myself in this instance in the addBeginRequest method so that if the name supplied is the top level update panel, I check to see which panel actually triggered the request (using my own logic), and then I have to rewrite the body of the request sent to the server.

I personally just wish this had been thought about properly in the first place!!

Giles gb

4/21/2008 6:15:52 AM

Great! Thanks!

duc vn

4/21/2008 11:49:16 AM

This is very helpful.

However, if the control triggering the postback is outside the update panel, in which case it has to be added to triggers collection, the panelID string does not containg the panel ID. It consist of the id of the ScriptManager control and the id of the control that triggered the postback. Any ideas how to retrieve the the panel id in this case?



thanks!

Zen us

4/22/2008 10:33:26 AM

Pingback from techtoolblog.com

Daily Find #58 | TechToolBlog

techtoolblog.com

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About your host.

Name of author Joe Stagner
?????

E-mail me Send mail

Calendar

<<  October 2008  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Pages

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in