How To Handle an async postback timeout in ASP.NET

ASP.NET is an open-source server-side web-application framework designed for web development to produce dynamic web pages developed by Microsoft to allow programmers to build dynamic web sites, applications and services.

In this article, I will show you how to handle Async PostBack in ASP.NET. Check out the following code snippet.

<%@ Page Language="C#" AutoEventWireup="true" %>

<script runat="server">
   protected void slow_postback(object sender, EventArgs e)
       // ten seconds is overkill... we timeout after one second (see ScriptManager below) 

<html xmlns="">
<head id="Head1" runat="server">
   <title>Handling an async postback timeout</title>
   <form id="form1" runat="server">
       <!-- This sets the timeout on async postbacks (i.e. UpdatePanel refreshes) to one second -->
       <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="1" />
       <asp:UpdatePanel ID="UpdatePanel1" runat="server">
               <asp:Button ID="Button1" runat="server" Text="Fast postback - no timeout" /> <br />
               <asp:Button ID="Button2" runat="server"
                Text="Slow postback - times out after one second"
 OnClick="slow_postback" /> <br />
               Last updated: <%= DateTime.Now %>

<script type="text/javascript">
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args) {
       if (args.get_error() && args.get_error().name ===
'Sys.WebForms.PageRequestManagerTimeoutException') {
           alert('Caught a timeout!');
           // remember to set errorHandled = true to keep from getting a
popup from the AJAX library itself 
Next Post Previous Post
No Comment
Add Comment
comment url