Ajax Control Toolkit – PageRequestManagerTimeOutException

February 5, 2010 PGS Team

How to avoid “PageRequestManagerTimeOutException” while using Ajax Control Toolkit?

I was having a problem when developing an ASP.NET Web Application using Ajax Control Toolikit.
On one of my Report pages, the constructed SQL query using LINQKit was pretty complex. It took a while for the SQL Server to return the results.
The complexity depends on the amount of specified filter parameters by the user. There are also calculations and transformations performed on the SQL results, which of course affect the request execution time.
This caused, that sometimes on my report page, when sending the Ajax request, the users browser noted a JavaScript error, instead of displaying the report.

First thought was to increase the Ajax PostBack Timeout. I can be set in the code behind – by default it’s set to 90 seconds:

ScriptManager.AsyncPostBackTimeout = 120; //in seconds

But what if there are more users requesting a report at the same time? At least I need to inform them, why they didn’t get what they were expecting.

There is a possibility in the Ajax Control Toolkit, to attach user JavaScript code when the request ends.
So if I attach my code that displays an alert message and/or redirects to an error page, that would be great! I could better handle this timeout.

So in the Master Page, after the ScriptManager control, I’ve added new JavaScript code:

Ajax Control Toolkit PageRequestManagerTimeoutException

Some explanation of this code sample:
– get the current Script Manager instance
– attach custom endRequest event function
– check if the request ends with an error of the type:
  Sys.WebForms.PageRequestManagerTimeoutException
– if the above^ condition is true, notice the Script Manager that this
  error was handled (prevent from JavaScript errors in users browser)
– finally redirect to custom error page (display error message, send error
  emails, etc.)

Additionally the reqManager._postBackSettings.panelID provides me extra informs about the update panel that started the request, because there are more of them on one page.

So this “simple” JavaScript code performs a timeout error check for all Ajax request in my Web Application.

Last posts