Web application users often report to developers that they are experiencing time-out issues while waiting for a process to complete. This process may be a Web-Service call from the back-end, a Stored Procedure call, a remote process call etc. So, it is quite obvious that execution time for them will vary and it will not be a wise decision to increase the client time-out setting accordingly. The solution to this problem is a client-callback, and again, it will not only solve time-out issues but also informs the user about the current state of the process.
Using the code
IHttpAsyncHandler to perform an
AsyncCallback. To do this, add a .ashx file to your project and inherit
IRequiresSessionState in your web handler class (in my example, it is
AsyncTaskHandler). In order to initiate an asynchronous call to an HTTP event handler, override "
IAsyncResult IHttpAsyncHandler.BeginProcessRequest(...)" and "
void EndProcessRequest(...)" in the web handler class.
public IAsyncResult BeginProcessRequest(HttpContext context,
System.AsyncCallback cb, object extraData)
object data = context.Request["ProcessNo"];
AsyncRequestResult result = new AsyncRequestResult(context, cb, data);
AsyncRequest request = new AsyncRequest(result);
ThreadStart start = new ThreadStart(request.Process);
Thread workerThread = new Thread(start);
Keep in mind the reusability of your code and object oriented programming concepts. Create a class file as
AsyncRequest which will handle the web request, and another class file as
function postRequest( url )
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST", url, true);
if (xmlhttp.readyState == 4)
var response = xmlhttp.responseText;
document.getElementById('lblMessage').innerHTML = response;
In ASP.NET 2.0, client callback can be implemented in a more easier way, though it still uses
XMLHTTP internally. The client callback feature really consists of two things: the
ICallbackEventHandler interface and the
Page.GetCallbackEventReference method. The architecture boils down to the following basic steps. The
XMLHTTP object under the hood). The request is then handled on the server side by a Web control that implements the