ASP.NET Ajax UpdatePanelNotifier: get notified of partial updates

UPDATE: The control has been added new features, check it out here

Sometime ago I wrote a post about how to get the ID of the UpdatePanel which triggered an asynchronous postback using the ATLAS July CTP and how to execute a custom Javascript function whenever the postback initiated and when it sent back its results. With the release of ASP.NET Ajax Extensions Beta the API has changed a lot and that code is no longer working, while he new API exposes now a whole new set of facilities which make it really easier to achieve the same functionality.

I wrote the control I once called UpdateProgressSignup from scratch and changed its name to a more meaningful one: UpdatePanelNotifier. What this control does is very similar to the UpdateProgress standard control, in that it executes some client-side code whenever a partial update is triggered and when the results are returned from the server. The difference is that instead of executing a determined function (showing and hiding a <div> element by manipulating the DOM) you can bind your custom javascript functions to those events, which in turn receive as input parameter the concerned UpdatePanel DOM element so that you can directly act on it, making it blink when the beginRequest event is fired and then shake when the endRequestEvent is fired, for example.

The control exposes the same properties as the standard UpdateProgress control beyond two new properties which let you enter the name of the functions you want to execute:

  • OnBeginRequest
  • OnEndRequest

Each function executed in response to those events will be passed the DOM element of the UpdatePanel concerned in the partial update, so that if you set the OnBeginRequest property to "alertPanelId", you'll have to write a javascript function called "alertPanelId" in you page which will have the following signature and will eventually do something like this:

function alertPanelId(panelElement)
{
alert(panelElement.id);
}

Note that the bound functions will be called only when the partial refresh is triggered by a control inside the UpdatePanel and not when it's an external trigger doing it, since in this case it's not yet possible to retrieve the Id(s) of the UpdatePanel(s) which will be refreshed in response to that action. Anyhow it seems that the ASP.NET Ajax Team is working on it and will eventually provide this facility in the final release.

You can watch a short screencast to get started fast. The source code is available on my main project's svn repository.

kick it on DotNetKicks.com

Published 19 November 2006 04:26 AM by simoneb
Filed under: ,

Comments

# SimoneB's Blog : Getting the ID of the UpdatePanel which triggered an asynchronous postback said on 18 November, 2006 08:16 PM

PingBack from http://dotnetslackers.com/community/blogs/simoneb/archive/2006/09/02/Getting-the-ID-of-the-UpdatePanel-which-triggered-an-asynchronous-postback.aspx

# DotNetKicks.com said on 18 November, 2006 08:18 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Greg Thomas said on 08 December, 2006 09:35 AM
I am using your control with latest Ajax Beta. I have not been successful yet using you control. My website Master Page has the webpage has Update Panel and Notifier control When update finishes, not javascript fires and no error messages. Maybe the ClientID name is different than you expect since is MasterPage? Any Ideas how I can debug to find issue? Thx Greg gthomas@cassinfo.com
# simoneb said on 08 December, 2006 07:01 PM

Hi Greg, I'm not having troubles using it in a paster page. Does it work for you when you don't use the master page?

# Robin Hobbensiefken said on 17 January, 2007 10:49 AM
Hey Simone, I'm trying to get your control to work and I'm not having a lot of luck. I'm working on a project where we started with Atlas and then moved over to AJAX. My coworker got AJAX working with all of our code and then a week or so later I downloaded and installed it and his changes no longer worked. It turns out MS changed the namespace from Microsoft.Web to System.Web. After a lot of playing around I managed to get everything working except for a couple of issues one of which would be solved with your control if I could get it to work. I need a javascript event to be thrown when a partial postback returns. (Your OnEndRequest event) The problem is I'm having similar issues to Greg Thomas. The page loads and the control doesn't throw any errors but it also doesn't fire the events. I created a simple web project for testing and I have stepped through the code in the debugger. The GetScriptReferences method gets called but the GetScriptDescriptors method doesn't and GetScriptDescriptors is the one that ties in the events from what I can tell. I am working to understand how the code works but it is slow going. Any suggestions you can offer would be greatly appreciated. You can reach me via email at hobben@gmail.com I would love to discuss this with you for a bit if you can afford the time.
# simoneb said on 17 January, 2007 11:40 AM

Hi Robin, the problem here is that the ASP.NET Ajax framework constantly upgrades and I cannot make a release of the components each time. I keep all my projects' code on my subversion repository located here: http://sourceforge.net/projects/busybox. There I try to keep the code up to date. I suggest you check out the source and try compiling the control yourself. The source is compatible with the RC1 version, so it whould work. If you still can't make it work feel free to contact me again and I will try to give you some support.

# TheLorax said on 17 January, 2007 12:29 PM

I have been playing with the source and running it in the debugger. To get it to work with the latest release I had to make a few changes like converting the Microsoft.Web namespace to System.Web. Once I made those changes it compiles just fine but the GetScriptDescriptors method doesn't ever seem to get called. Can you tell me when this gets called (and how if possible) in the version you have working? I found an IScriptControl tutorial on the AJAX website and in their example, they override the Render event which I don't see in your code. In the tutorial, the Render event uses the script manager to call the RegisterScriptDescriptors method.  ( sm.RegisterScriptDescriptors(this); ) I'll keep looking but I was wondering why you don't call RegisterScriptDescriptors anywhere in the code.

# TheLorax said on 17 January, 2007 03:30 PM

Ok, I'm making headway. I figured out how to DL the source from sourceforge and built the entire BusyBoxDotNet project (I had been using the zip you link in the article before) and after a few minor changes I have it going except it doesn't seem to be able to find my JS functions.  All of the code now executes (it helps having the right source) and the code gets to the  set_customEndRequest function in the UpdatePanelNotifier.js file where it tries the Function.parse(value) call. The Type.parse code gest down to where it tries an eval(typeName) where typeName is my function name at which point I get an "Microsoft JScript runtime error: 'EndFn' is undefined" error. EndFn is the name I used for my custom end request. I had a begin request function and was getting the same error but I removed it to see if it would get to the end request. So from what I can tell it's not finding EndFn in my file. I'll keep plugging away.

BTW thanks for putting this code together! It's nice seeing a reply the same day as I posted my initial post too. :) I hope I don't come across as too demanding with my posts. I just really want to see this working.

# TheLorax said on 17 January, 2007 04:14 PM

Yay!! I managed to get it working and not surprisingly it was operator error on my part ;)  I didn't have my Javascript function block declared correctly and so it couldn't find the methods.  Thanks again for posting this code online!

# simoneb said on 17 January, 2007 06:12 PM

Glad you solved, feel free to contact me for any issues you may find.

# Buspar. said on 29 July, 2008 12:13 PM

Buspar experience.

# Propecia online lowest prices for hair loss reduce. said on 04 August, 2008 05:05 AM

Propecia. Do propecia side effects go away. Propecia merck propecia online uk. Propecia online uk. Buy propecia.

This site

Search

Go

This Blog

News

Syndication

Sponsors

  • MaximumASP