Geoffroy’s Weblog

October 15, 2008

Can you register more than one postback method with an event of the PageRequestManager?

Filed under: AJAX, JavaScript — gseive @ 6:02 pm

 

For the past 10 months I worked on a project using ASP.NET AJAX and the server-centric development model with ScriptManager, UpdatePanel and PageRequestManager.

 

Something I have not read about, but that was actually fairly easy to verify, is “can you register more than one postback method with an event of the PageRequestManager?”.

So I modified the code of a really simple, yet interesting, example that shows how to use the initializeRequest event to allow an asynchronous postback to be canceled. It comes from MSDN at the page for the Sys.WebForms.InitializeRequestEventArgs Class.

Here’s the code I added:

                Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(AddMyMessage);

and

                function AddMyMessage(sender, args)

                {

                    var aspan = $get(messageElement);

                    aspan.innerHTML = aspan.innerHTML + ” it works!”;

                }

 

As you will observe the answer is yes, it can be done.

 

A good read in Partial-Page Rendering Overview is Working with PageRequestManager Events.

 

A more complete example can be found at Canceling an Asynchronous Postback.

 

Some good background information can be found in the section UpdatePanel Control Overview. The AJAX Server Controls section it is a part of also introduces the ScriptManager control, the Timer control and the UpdateProgress control.

 

 

Unfortunately some examples are not coded properly.

 

 

Another good source of information is the book “ASP.NET AJAX in Action”. I found it informative and well organized, covering very well all the different aspects of ASP.NET AJAX.

ASP.NET AJAX in Action

  

Hope that helps.

Create a free website or blog at WordPress.com.