A minor design flaw in Microsoft AJAX library
Microsoft AJAX Library is a good javascript library for building AJAX components, behaviours, and controls. It is widely used by AJAXControlToolkit. Microsoft AJAX Library has a central class called PageRequestManager. A singleton object of this class is initialized when you put an UpdatePanel in the aspx page.
PageRequestManager provides events which you can handle. A common use is to cancel the AJAX request if another AJAX request is running. This is the common structure of javascript code that uses the PageRequestManager.
var prm = Sys.Webforms.PageRequestManager.get_instance(); prm.add_beginRequest(function() {});
There are two events that are raised before a AJAX request is invoked: initializeRequest, beginRequest. The request body can be got using code like this:
var prm = Sys.Webforms.PageRequestManager.get_instance(); orm.add_initializeRequest( function(sender, args) { alert(args.get_request().get_body()); });
I have a requirement where I want to modify the values of a textbox when some conditions are met. This should be done after the user clicks the button but before the AJAX request is invoked. I have multiple buttons / GridView links in the page which are AJAX enabled.
I hooked into the PageRequestManager initializeRequest(). I modified the textbox values. However, the server did not get the modified values. It appears that the request body is prepared before the initializeRequest() event is raised.
The worst part is that the library does not allow me to modify the request body using a simple API. Sys.Net.WebRequest has a method to set the request body using the set_body() function. But, there is no programatic API to set the value of the textbox using an ID or name.
One more reason why the Microsoft AJAX library did not become popular!
Category : ASP.NET AJAX


