Sunday, August 14, 2011

AJAX Page life cycle


Asynchronous Postback

An asynchronous postback sends some page data to the server, receives a response, and updates a part of the page. Assume the following scenario for an asynchronous postback:
  • The page contains a ScriptManager control, and the control's SupportsPartialRendering andEnablePartialRendering properties are both true.
  • The page contains an UpdatePanel control, and the control's ChildrenAsTriggers property is true.
  • A button inside the UpdatePanel control initiates an asynchronous postback.
  • A response from the server is returned successfully.
The following client events occur, in this order:
  1. The button inside the UpdatePanel is clicked, which initiates an asynchronous postback.
  2. The PageRequestManager instance raises the initializeRequest event.
  3. The PageRequestManager instance raises the beginRequest event.
  4. The request is sent to the server.
  5. The response is received by the client.
  6. The PageRequestManager instance raises the pageLoading event.
  7. The PageRequestManager instance raises the pageLoaded event.
  8. The Application instance raises the load event.
  9. The PageRequestManager instance raises the endRequest event.
For more information, see Working with Partial-Page Rendering Events.
Note that the load event of the Application instance is raised after the PageRequestManagerpageLoadedevent and before its endRequest event.

Multiple Asynchronous Postbacks

Multiple asynchronous postbacks can occur when users initiate a new request before a previously initiated request has finished processing on the server or in the browser. Assume the following scenario for multiple asynchronous postbacks:
  • The page contains a ScriptManager control and the control's SupportsPartialRendering andEnablePartialRendering property are both true.
  • The page contains an UpdatePanel control.
  • A button inside the UpdatePanel control that initiates an asynchronous postback is clicked two times. The second click occurs while the server is processing the request initiated by the first click.
  • A response to the first request is returned successfully from the server.
The following client events occur, in this order:
  1. A button inside the UpdatePanel is clicked, which initiates an asynchronous postback.
  2. The PageRequestManager instance raises the initializeRequest event.
  3. The PageRequestManager instance raises the beginRequest event.
  4. The request is sent to the server.
  5. The button is clicked again, which initiates a second asynchronous postback.
  6. The PageRequestManager instance raises the initializeRequest event for the second button click.
  7. The PageRequestManager instance raises the endRequest event for the first button click.
  8. The PageRequestManager instance raises the beginRequest event for the second button click.
  9. The request initiated by the second click is sent to the server.
  10. The response is received for the second click.
  11. The PageRequestManager instance raises the pageLoading event.
  12. The PageRequestManager instance raises the pageLoaded event.
  13. The Application instance raises the load event.
  14. The PageRequestManager instance raises the endRequest event.
The default behavior of asynchronous postbacks is that the most recent asynchronous postback takes precedence. If two asynchronous postbacks occur in sequence, and if the first postback is still being processed in the browser, the first postback is canceled. If the first postback has been sent to the server, the server processes the second request when it arrives and does not return the first request. For information about how to give precedence to a specific asynchronous postback, see Giving Precedence to a Specific Asynchronous Postback.