Wednesday, November 2, 2011

Timeout problem with AJAX... Solved

While working with ASP.Net applications, you might have got below mentioned runtime error.

Sys.WebForms.PageRequestManagerTimeoutException - The server request timed out – error

I recently came across the error. After hitting a button on my page, I was doing some heavy SQL operations on thousands of records and thus it was taking some time to render the output (around 2 minutes). But before I could get the result, I was getting this runtime error.

This timeout was different than the Page Request Timeout which was set to 10minutes (600 seconds). After some investigation I realized that this error was coming from AJAX Extension framework. Bingo.

When you are using AJAX on your page, there is a default timeout of 90 seconds for each Asynchronous postback request. And if your request is taking more than 90 seconds AJAX Extension callback framework will timeout. No wonder why my application was breaking.

So, how to get rid of this problem? Well its simple, just override the default timeout for AJAX request and you will be done. All you have to do is to set your desired timeout period for AsyncPostBackTimeOut property of ScriptManager as shown below.

<asp:ScriptManager ID="ScriptManager1" runat="server"

AsyncPostBackTimeOut="600" >

asp:ScriptManager>

As I mentioned earlier, the default value of the AsyncPostBackTimeOut property is 90 seconds.

So that’s it, now your application will work properly even if any AJAX request takes more than 90 seconds to complete.

Hope you find this post useful. Feel free to provide comments and feedbacks.