473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Identifying the refreshed update panel

31
Hi,

I have several update panels in my page. i want to call different javascript methods after the update panels are refreshed . i have attached the Sys.WebForms.PageRequestManager.getInstance().add_ endRequest(MyMethod); at the end of the page and after an update panel is refreshed it is triggered.
that method is like MyMethod(sender,args) .

my problem is how can i identify which update panel is refreshed in side the MyMethod function?

Thanks
Jun 25 '09 #1
1 7512
Frinavale
9,735 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
  3.   //Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
  4.  
  5.    function endRequestHandler(sender, args) {
  6.         var postbackSettings = sender._postBackSettings.panelID;
  7.         alert(postbackSettings);
  8.     }
  9.     //function pageLoadedHandler(sender, args) {
  10.     //    var updatedPanels = args.get_panelsUpdated();
  11.     //    for (i = 0; i < updatedPanels.length; i++) {
  12.     //        alert(updatedPanels[i].id);
  13.     //    }
  14.  
  15.     //}
  16.  
  17. </script>
  18. <asp:UpdatePanel ID="Update1" runat="server">
  19.     <ContentTemplate>
  20.         <asp:Button ID="buttonInUpdate1" runat="server" Text="Button In Update1" />
  21.     </ContentTemplate>
  22. </asp:UpdatePanel>
  23. <asp:UpdatePanel ID="Update2" runat="server">
  24.     <ContentTemplate>
  25.         <asp:Button ID="buttonInUpdate2" runat="server" Text="Button In Update2" />
  26.     </ContentTemplate>
  27. </asp:UpdatePanel>
  28.  
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
Jun 25 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lo?c Mah? | last post by:
Hello I have a problem to update the content of a wx.Panel already displayed after changing a variable, used to define the wx.Panel content. I have the following elements in my code: ...
0
by: arunprabu | last post by:
Hi, I have a problecm with the AJAX request in my webpage. I have some filters on top of the page. I have a submit button and an empty div below the filters. Some of the filters have ajax...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
2
by: DanWeaver | last post by:
I have a page where layout of buttons and listboxes etc is important - I would like to make use of Ajax Update panel to asynchronously update various part of the page- in Vis studio whenever I use...
1
by: gabe | last post by:
How do you call a client side javascript callback method after an update panel has posted back to the server? I have two update panels (A + B) with a gridview in each panel. GridView B has a...
5
by: HockeyFan | last post by:
We have an update panel that has a gridview with checkboxes and other items in each row. We went to the RowCreated event in the codebehind, to set an attribute on a checkbox in each row, to...
1
by: Microsoft Newsserver | last post by:
HI Im developing a solution in vs2005 with ajex extensions. Essentially I have three custom controls which render tables a representation as shown below. The problem is that when any of...
0
by: nityaprashant | last post by:
hello.. i used ajax update panel in my cart form now i want to use paypal button for redirect online transaction because of ajax update panel round trip is not possible.. so paypal button gives...
2
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.