Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

C#
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);
   }


C#
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
Comments
AmitGajjar 13-Sep-12 7:06am    
can you post code of your aspx page?
[no name] 13-Sep-12 7:53am    
rajeev,

Is the thread.sleep part of the functionality or are you just trying to experiment?
Ed Nutting 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
[no name] 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">
<contenttemplate>
<asp:TextBox ID="TextBox1" runat="server">





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

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

<contenttemplate>

<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

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

the .aspx page
XML
<%@ 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;

C#
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
 
Share this answer
 
v3
Comments
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900