Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Ajax
Hello,
There are two update panel containing two text boxes. I have two buttons thats are triggered with these update pannels asynchronously.

On Cick even of the button I am writing code like as

protected void Button1_Click(object sender, EventArgs e)
   {
       //Server.Transfer("http://www.google.co.in/");
       //Response.Redirect("http://www.google.co.in/");

       TextBox1.Text = "Ajax Clicked";
       Thread.CurrentThread.ThreadState..Sleep(100000);
   }

protected void Button2_Click(object sender, EventArgs e)
   {
       TextBox2.Text = "Ajax Asynchrnously clicked";
   }

In this scenario, The AJAX not showin the asynchrnous behaviour. Neither first first Text box is updating nor second if we click on button one first.

Thank you to let me know the reason behind this situation.

Regards
Rajeev
Posted 13-Sep-12 1:45am
Comments
@amitgajjar at 13-Sep-12 7:06am
   
can you post code of your aspx page?
Jyothikarthik_N at 13-Sep-12 7:53am
   
rajeev,

Is the thread.sleep part of the functionality or are you just trying to experiment?
Ed Nutting at 13-Sep-12 13:54pm
   
Erm...surely the HTTP AJAX request would time out before your Thread.Sleep ends resulting in no response to your AJAX request and so the textbox wouldn't be updated. The default (I think) is a 30 to 60 second timeout, you will have to increase this to 100 (if not more) for your code to work. If that doesn't fix it in itself, it is almost certainly going to be a problem.

Hope this helps,
Ed
vithal wadje at 14-Sep-12 2:03am
   
use this code it might help you to fix your Problem..

the .aspx page

<pre lang="text"> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax.aspx.cs" Inherits="ajax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">

<asp:Timer ID="Timer1" runat="server">




<table>
<tr>

<td>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<asp:TextBox ID="TextBox1" runat="server">





</td>
</tr>
<tr>
<td>

<asp:UpdatePanel ID="UpdatePanel2" runat="server">



<asp:TextBox ID="TextBox2" runat="server">







</td>




</tr>

<tr>

<td> <asp:Button ID="Button1" runat="server" Text="Button1"
onclick="Button1_Click" /> </td>
<td> <asp:Button ID="Button2" runat="server" Text="Button2" onclick="Button2_Click" /> </td>
</tr>





</table>
</form>
</body>
</html>
</pre>

the aspx.cs file


<pre lang="c#">





using System;
using System.Threading;

public partial class ajax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Ajax Clicked";

Thread.Sleep(1000);
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox2.Text = "Ajax Asynchrnously clicked";
}
}




</pre>


I hope this will helps you

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use this code it might help you to fix your Problem..

the .aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax.aspx.cs" Inherits="ajax" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
&lt;html xmlns="http://www.w3.org/1999/xhtml">
&lt;head runat="server">
    &lt;title>&lt;/title>
&lt;/head>
&lt;body>
    &lt;form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Timer ID="Timer1" runat="server">
</asp:Timer>
 

 
   <table>
   <tr>
 
   <td>
 
     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     </ContentTemplate>
     </asp:UpdatePanel>
 

 
   </td>
   </tr>
   <tr>
   <td>
 
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
 
       <ContentTemplate>
 
         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
 
       </ContentTemplate>
 

  </asp:UpdatePanel>
 

   </td>
 

 

   </tr>
 
      <tr>
 
      <td> <asp:Button ID="Button1" runat="server" Text="Button1"
        onclick="Button1_Click" />          </td>
<td>   <asp:Button ID="Button2" runat="server" Text="Button2" onclick="Button2_Click" />    </td>
      </tr>
 

 

 
    </table>
    &lt;/form>
&lt;/body>
&lt;/html>

the aspx.cs file

using System;
using System.Threading;

public partial class ajax : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "Ajax Clicked";
 
        Thread.Sleep(1000);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox2.Text = "Ajax Asynchrnously clicked";
    }
}


I hope this will helps you
  Permalink  
v3
Comments
sudhir@123 at 14-Sep-12 4:19am
   
very useful article for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,534
1 OriginalGriff 6,258
2 Peter Leow 2,534
3 Maciej Los 2,308
4 Abhinav S 2,274


Advertise | Privacy | Mobile
Web03 | 2.8.150414.1 | Last Updated 14 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100