我想在点Button后让它5秒内失效,请用AJAX。<script runat="server">
void WaitFiveSeconds(object o, EventArgs e)
{
//这里怎么写?
System.Threading.Thread.Sleep(5000);
Button1.Enabled = false;
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AJAX</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server"
Text = "Do something" OnClick="WaitFiveSeconds" /><br />
<asp:Label ID="Label1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div style="position:absolute; left:200px; top:150px;
padding:40px;">
</div>
Loading,Please wait for 5 seconds ...
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>
void WaitFiveSeconds(object o, EventArgs e)
{
//这里怎么写?
System.Threading.Thread.Sleep(5000);
Button1.Enabled = false;
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AJAX</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server"
Text = "Do something" OnClick="WaitFiveSeconds" /><br />
<asp:Label ID="Label1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div style="position:absolute; left:200px; top:150px;
padding:40px;">
</div>
Loading,Please wait for 5 seconds ...
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>
解决方案 »
- .ent 关于vs问题 在网上下载的程序打不开
- GridView如何创建多行合并的表格,具体如图所示
- 再次求救--->用Repeater做一张人事表格,怎样显示照片?
- 怎样将字符串“2006/1/1 13:23”分别取出其中的年和月和日,需要转先换成日期型吗?
- MSXML2.XMLHTTP 异步执行的onreadystatechange 问题
- XDJM们,哪儿有access + C#的论坛下载啊
- Grid单元前景色的问题
- javascript
- 我用VB。NET做了个DLL是打印ACTIVEREPORT的。用ASP。NET调用出现打印错误,请高手指点,急!谢谢
- 请指点,,搜索引擎怎么写??搜索网页和文件系统的东东??请出手
- javascript效果积累帖(123cha网站中的点击复制效果)
- .NET怎样向Oracle中的大字段类型(clob)里面插入值
然后用Ajax转到后台,在后台System.Threading.Thread.Sleep(5000);
再返回到前台,设置Button的Enabled = true
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
设置n秒钟后失效(this.Button1, 5);
} private void 设置n秒钟后失效(WebControl wc, int n)
{
wc.Page.ClientScript.RegisterStartupScript(wc.GetType(), "disable", "setTimeout(function(){document.getElementById('" +
wc.ClientID + "').disabled='disabled';}," + (n * 1000).ToString() + ");", true);
}
</script><!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>demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
<%@ Page Language="C#" %><script runat="server"> private void 设置n秒钟后失效(WebControl wc, int n)
{
ScriptManager.RegisterStartupScript(wc, wc.GetType(), "disable", "setTimeout(function(){document.getElementById('" +
wc.ClientID + "').disabled='disabled';}," + (n * 1000).ToString() + ");", true);
} protected void Button1_Click(object sender, EventArgs e)
{
设置n秒钟后失效(this.Button1, 5);
}</script><!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>demo</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
我试验了你给的demo,效果是点Button5秒以后失效,而非5秒以内一直失效,5秒后可以再点。
呵呵,这个呀。改一下:<%@ Page Language="C#" %><script runat="server"> private void 设置n秒钟后生效(WebControl wc, int n)
{
ScriptManager.RegisterStartupScript(wc, wc.GetType(), "disable", "setTimeout(function(){document.getElementById('" +
wc.ClientID + "').disabled=null;}," + (n * 1000).ToString() + ");", true);
} protected void Button1_Click(object sender, EventArgs e)
{
this.Button1.Enabled = false;
设置n秒钟后生效(this.Button1, 5);
}</script><!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>demo</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>