如何防止按钮连续点击 点击后disabled掉处理完再恢复 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <input type="submit" id="btnSub" onclick="javascript:this.disabled=true;" value="提交" /> 点击后disabled掉处理完再恢复,再从数据库中建立唯一键值,不能插入重复的内容,通过捕获异常来提示行于客户的交互 点击完提交按钮,将它禁用(disabled=true),后台处理完以后redirect回来 <script language="javascript"> setTimeout('document.getElementById("btn").disabled=false',5000); </script><INPUT id=btn onclick="this.disabled=true" type="button" value="Button"> 刚才有错 只能使用input button 不能用submit按钮 或服务器端按钮testBtn.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testBtn.aspx.cs" Inherits="testBtn" %><!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"> <div> <input id="Button1" type="button" onclick="this.disabled=true;" value="提交" onserverclick="Button1_ServerClick" runat="server" /></div> </form></body></html>.csusing System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class testBtn : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_ServerClick(object sender, EventArgs e) { Response.Write("ttttttttttttttttttt"); System.Threading.Thread.Sleep(5000); Page.RegisterStartupScript("enBtn", "<script>document.getElementById('Button1').disabled=false;</script>"); }} //为查询数据时防止多次提交而设置 保证 __doPostBack(eventTarget, eventArgument) 正确注册page_load的时候,不要放在if(!this.IsPostBack)中this.Page.GetPostBackEventReference(this.btn_Search);--------------------------------------------------------------------------------- this.btn_Search.Attributes.Add( "onclick" , "if(SearchCheck()){this.disabled=true;this.value='数据查询中...';"+this.Page.GetPostBackEventReference(this.btn_Search)+";}else{return false;}" ); //主要是用来防止多次提交而设置 this.Page.GetPostBackEventReference(this.btn_Search)是用__doPostBack来提交,保证按钮的服务器端click事件执行 加入原因:当disabled=true时不能执行服务器事件 或者可以将 下面的函数加到 pageload中不缓存客户端protected void NoCatchOutPage() { HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Expires = 0; HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1); //DateTime.Now.AddDays(-1); HttpContext.Current.Response.AddHeader("pragma", "no-cache"); HttpContext.Current.Response.AddHeader("cache-control", "private"); HttpContext.Current.Response.CacheControl = "no-cache"; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetAllowResponseInBrowserHistory(true); } ASPxGridView单击一行触发事件 如何用ajax技术获取aspx中的服务器对象值 “mscorlib.dll”类型的异常 十万火急!access数据库更新的奇怪问题!(跪求啊!!!) 我们开发WEB程序,如果使用Sql Server 2005 的话,什么样的版本就足够了。 请教,如何绑定成员中的数组数据??? asp.net 超链接标签问题 发布一个大技巧,是一个很偷懒的方法,不要错过呀。 咳!大伙往这看,深入了解web.config 求梅花雨日历3.0 请高手们帮助看看代码有什么问题谢谢 怎样让 menu 控件调用 javascript 函数?
处理完再恢复,
再从数据库中建立唯一键值,不能插入重复的内容,通过捕获异常来提示行于客户的交互
setTimeout('document.getElementById("btn").disabled=false',5000);
</script>
<INPUT id=btn onclick="this.disabled=true" type="button"
value="Button">
testBtn.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testBtn.aspx.cs" Inherits="testBtn" %><!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">
<div>
<input id="Button1" type="button" onclick="this.disabled=true;" value="提交" onserverclick="Button1_ServerClick" runat="server" /></div>
</form>
</body>
</html>.csusing System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class testBtn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_ServerClick(object sender, EventArgs e)
{
Response.Write("ttttttttttttttttttt");
System.Threading.Thread.Sleep(5000); Page.RegisterStartupScript("enBtn", "<script>document.getElementById('Button1').disabled=false;</script>");
}
}
page_load的时候,不要放在if(!this.IsPostBack)中
this.Page.GetPostBackEventReference(this.btn_Search);
--------------------------------------------------------------------------------- this.btn_Search.Attributes.Add( "onclick" , "if(SearchCheck()){this.disabled=true;this.value='数据查询中...';"+this.Page.GetPostBackEventReference(this.btn_Search)+";}else{return false;}" );
//主要是用来防止多次提交而设置 this.Page.GetPostBackEventReference(this.btn_Search)是用__doPostBack来提交,保证按钮的服务器端click事件执行 加入原因:当disabled=true时不能执行服务器事件
不缓存客户端protected void NoCatchOutPage()
{
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1); //DateTime.Now.AddDays(-1);
HttpContext.Current.Response.AddHeader("pragma", "no-cache");
HttpContext.Current.Response.AddHeader("cache-control", "private");
HttpContext.Current.Response.CacheControl = "no-cache";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(true);
}