Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Asynchronous and Synchronous Page Processing Determination

0.00/5 (No votes)
6 Nov 2011 1  
An easy way to understand Ajax help in ASP.NET
Using this simple trick, everyone can easily ensure that page processing is synchronous or asynchronous.
XML
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableHistory="true">
       </asp:ScriptManager>
       <asp:UpdatePanel ID="UpdatePanel1" runat="server">
         <ContentTemplate>
             <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
             <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
             <asp:Timer ID="Timer1" runat="server" Interval="40000" ontick="Timer1_Tick">
             </asp:Timer>
             <asp:Label ID="Label3" runat="server"></asp:Label>
         </ContentTemplate>

       </asp:UpdatePanel>

Code Behind


C#
protected void Page_Load(object sender, EventArgs e)
       {
           if (ScriptManager1.IsInAsyncPostBack==true)
           {
               Label1.Text = "Page processing is Ashnchronuslly..";
           }
           else
           {
               Label1.Text = "Page Processing is Syncrhonulsy...";
           }
       }

       protected void Timer1_Tick(object sender, EventArgs e)
       {
           if (ScriptManager1.IsInAsyncPostBack == true)
           {
               Label2.Text = DateTime.Now.ToString();
           }
}

Description


For the First Request only Synchronous Processing is done.
                       Page Processing is Syncronously... Label
For the Second Request onwords
          Page Processing IS Asynchronously.. 11/1/2011 12:37:27 PM

Yes, for every 40 secs updatedpanel content is updated asynchronusly with the help of Timer Control Tick event, the updated time will be displayed in Lable2. We can ensure many things for every request and response internals with the help of any Firebug console window or any browsers WebDevelopment tools.

Like below for every 40 seconds:


POST http://localhost:1165/PageProces.aspx 200 OK 520ms	
POST http://localhost:1165/PageProces.aspx 200 OK 348ms	
POST http://localhost:1165/PageProces.aspx 200 OK 370ms	
POST http://localhost:1165/PageProces.aspx 200 OK 336ms	
POST http://localhost:1165/PageProces.aspx 200 OK 362ms	
POST http://localhost:1165/PageProces.aspx 200 OK 382ms	
POST http://localhost:1165/PageProces.aspx 200 OK 378ms	

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here