Anda di halaman 1dari 3

Asynchronous postback events

The following diagram illustrates an asynchronous postback event to initiate partial rendering of
a page at runtime. The green circles indicate the order in which events occur to initiate and
process the postback. A description of each step is provided.

1. By default a server control button is rendered as a Hypertext Markup Language (HTML)

input element that submits the form in which it resides. When a ScriptManager control
is present on a page, all calls to form.submit() or _doPostBack are intercepted by a
handler added during Sys.WebForms.PageRequestManager initialization (initial page
load). At runtime, these calls, whether synchronous or asynchronous, are redirected to
the PageRequestManager._onFormSubmit() private function.
In this case, clicking the button submits the form and triggers an asynchronous
postback since the button resides in an UpdatePanel control. Controls outside an
UpdatePanel control need to register with the ScriptManager control to initiate an
asynchronous postback. A new AJAX object, Sys.Web.WebRequest, is created,
properties are set, and the Web request is invoked.
2. When the Web request is invoked, it uses Sys.Net.XmlHTTPExecutor to create an
XMLHttpRequest object. The XMLHttpRequest object connects to the server and
submits the request. The request includes a reference to the ScriptManager control and
the control that initiated the postback, a custom header (x-microsoftajax), the view
state, and the event validation information.

The following code shows an example request. Some of the general header information
has been excluded:
POST / MyWebsite / SimplePartialPostback.aspx HTTP / 1.1 x microsoftajax: Delta =
true Content - Type: application / x - www - form - urlencoded
ScriptManager1 =
UpdatePanel1 | Button1 & __EVENTTARGET = &__EVENTARGUMENT =


2FwEWAgK4 % 2FtfdBQKM54rGBpRqW1kQZkPGexH7 % 2B3rIj % 2BivSiMJ &

Button1 = Get %
20Server % 20Time
3. On the server, the ScriptManager control manages all page and control rendering via
interaction with the ASP.NET AJAX System.Web.UI.PageRequestManager object and
System.Web.UI.ScriptManager.IPage interface. PageRequestManager determines if the
postback is asynchronous and initiated by a client using ASP.NET AJAX JavaScript. It
searches for the x-microsoftajax header to contain the argument\value pair
Delta=true. If true, the ScriptManager control intercepts all page content rendering
and generates the HTTP response. If an UpdatePanel control is to be rerendered during
the postback, all controls it contains are completely rerendered, even if they did not
The first part of the partial postback response contains the raw rerendered content.
The next section includes a set of serialized values to track view state, event
validation, asynchronous postback controls, UpdatePanel controls, and triggers. The
final section is optional and contains custom data items and script includes statements
registered with the ScriptManager control during postback processing on the server.
The following code shows an example response. Some of the general header
information has been excluded:

HTTP / 1.1 200 OK Server: Microsoft - IIS / 5.1 Date: Thu, 08 Nov 2007
01: 07: 21
GMT Content - Type: text / plain;
charset = utf - 8 172 | updatePanel | UpdatePanel1 |

< input type =

"submit" name =
"Button1" value = "Get Server Time" id = "Button1"/

>< span id =

11 / 7 / 2007 5: 07: 21 PM <

/ span >

| 1e0128 | hiddenField |


cvMjAwNyA1OjA3OjIxIFBNZGRkYeVef8HDv2pb / 77ZnVtAjeVPeVI =
hiddenField | __EVENTVALIDATION |

| 48 |

wEWAgK18bqfBQKM54rGBoFX9wkAeMuxT4L2336BrKkHwERo | 0 |
asyncPostBackControlIDs ||

| 0|postBackControlIDs ||

| 13 |

updatePanelIDs || tUpdatePanel1 | 0 | childUpdatePanelIDs ||

| 12 |

panelsToRefreshIDs || UpdatePanel1 | 2 | asyncPostBackTimeout || 90|26 |

formAction || SimplePartialPostback.aspx | 13 | pageTitle || Untitled
Page | 0
4. The partial postback response is returned to the browser client and processed by the
Web request that wrapped the initial request. The body of the response is directed to
the PageRequestManager._onFormSubmitCompleted () function by a handler registered
via the WebRequest.add_completed function.
The _onFormSubmitCompleted () function contains the logic to parse the body of the
response. The logic updates page elements and view state, executes JavaScript
includes statements, passes data items to their respective handlers, and modifies
ASP.NET AJAX JavaScript components dynamically.