问题描述
你好,
有两个包含两个文本框的更新面板.我有两个按钮,这些按钮是通过这些更新面板异步触发的.
在Cick上,甚至在按下按钮时,我都在编写类似
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";
}
在这种情况下,AJAX不会显示在异步行为中.如果先单击一个按钮,则第一个第一个文本框不会更新,第二个也不会更新.
谢谢让我知道这种情况背后的原因.
问候
Rajeev
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
推荐答案
<%@ 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: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>
</form>
</body>
</html>
aspx.cs文件
使用系统;
使用System.Threading;
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
这篇关于Thread.sleep()中断AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!