Click here to Skip to main content
12,446,296 members (53,451 online)
Rate this:
 
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 0:45am
Comments
@amitgajjar 13-Sep-12 7:06am
   
can you post code of your aspx page?
Jyothikarthik_N 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
vithal wadje 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">

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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 14 Sep 2012
Copyright © CodeProject, 1999-2016
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