ASP.NET AJAX framework provides various page events that are raised during processing ajax requests.
Following table shows details of Events,
| Event Name | Description |
|---|---|
| beginRequest Event | Raised before processing of an asynchronous postback starts and the postback request is sent to the server. |
| endRequest Event | Raised after an asynchronous postback is finished and control has been returned to the browser. |
| initializeRequest Event | Raised during the initialization of the asynchronous postback. |
| pageLoaded Event | Raised after all content on the page is refreshed as the result of either a synchronous or an asynchronous postback. |
| pageLoading Event | Raised after the response from the server to an asynchronous postback is received but before any content on the page is updated. |
Uses
- beginRequest: can be used to call custom script to set a request header or to start an animation that notifies the user that the postback is being processed.
- endRequest: can be used to provide a notification to users or to log errors.
- initializeRequest: can be used to cancel a postback.
- pageLoaded/ pageLoading: can be used to provide a custom transition effect for updated content.
How To Use
- Register beginRequest event syntax,
Sys.WebForms.PageRequestManager.instance.add_beginRequest (beginRequestHandler)
- Remove beginRequest event syntax,
Sys.WebForms.PageRequestManager.instance.remove_beginRequest (beginRequestHandler)
Example
Add following script into your page,
function pageLoad() {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
prm.add_beginRequest(beginRequestHandler);
prm.add_pageLoaded(pageLoaded);
}
function InitializeRequest(sender, args) {
//TODO: write InitializeRequest code here
}
function BeginRequestHandler(sender, args) {
//TODO: write BeginRequestHandler code here
}
function EndRequest(sender, args) {
//TODO: write EndRequest code here
}
function pageLoaded(sender, args) {
//TODO: write pageLoaded code here
}
References:
WebSite: http://www.asp.net/AJAX/Documentation
Demo: http://amolwable.com/demo/ajaxevents/AjaxEventsDemo.aspx
Download: http://amolwable.com/demo/ajaxevents/AjaxEventsDemo.zip