Thursday, January 17, 2008

Enabling an asynchronous web page

Step 1. Add the Async="true" attribute the page directive:


eg: Page Language="C#" Async="true" AutoEventWireup="true"

Step 2. Create events to start and end the asynchronous code that implements the System.Web.IHttpAsyncHandler.BeginProcessRequest and System.Web.IHttpAsyncHandler.EndProcessRequest


eg: IAsyncResult BeginGetAsyncData(Object src, EventArgs args, AsyncCallback cb,

Object state)
{ }

void EndGetAsyncData(IAsyncResult ar)
{ }



Step 3. call the AddOnPreRenderCompleteAsync method to declare the event handlers:


eg: BeginEventHandler bh=new BeginEventHandler(this.BeginGetAsyncData);
EndEventHandler eh= new EndEventHandler(this.EndGetAsyncData);
AddOnPreRenderCompleteAsync (bh,eh)

No comments: