如何禁止重复提交
来源:互联网 发布:淘宝lolita店铺推荐 编辑:程序博客网 时间:2024/04/28 22:34
一开始我使用了
this.button_OK.Attributes.Add("onclick", "window.document.getElementById(’" + this.Button_OK.ClientID + "’).disabled = true;")
但这样做的结果是server端的button click处理函数不会被执行.
正确的做法是在Page Load中添加代码:
//.net 2.0
string script = ClientScript.GetPostBackEventReference(this.Button_OK, null);
if (!Page.IsPostBack)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("window.document.getElementById(’" + this.Button_OK.ClientID + "’).disabled = true;");
sb.Append(script);
sb.Append(";");
this.Button_OK.Attributes.Add("onclick", sb.ToString());
}
// .net 1.0
string script = this.GetPostBackEventReference(this.button_OK);
If (!Page.IsPostBack)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("window.document.getElementById(’" + this.button_OK.ClientID + "’).disabled = true;");
sb.Append(script);
sb.Append(";")
this.button_OK.Attributes.Add("onclick", sb.ToString());
}
GetPostBackEventReference会生成html代码:
<script type="text/javascript">
<!–
var theForm = document.forms[’form1′];
if (!theForm)
{
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// –>
</script>
生成的script值为__doPostBack(’Button_OK’,'’)
- 如何禁止重复提交
- 如何禁止重复提交
- 如何禁止重复提交
- C#禁止重复提交
- 禁止表单重复提交
- C#禁止重复提交
- 禁止表单里重复提交
- ASP.NET禁止重复提交
- ASP.NET禁止重复提交
- asp.net禁止重复提交
- struts2禁止表单重复提交
- Form禁止重复提交总结
- 小TIPS:禁止表单里重复提交
- 前端禁止多次重复提交表单
- 小TIPS:禁止表单里重复提交
- struts2禁止表单重复提交 demo
- 禁止重复提交(JavaScript控制表单…
- 如何避免重复提交
- 暑假社会调查报告--.net PK J2EE
- 全景图技术
- 开门红
- 无Cookie 的 Session State
- GridView的使用
- 如何禁止重复提交
- 如何用enter key正确提交Form
- “是否同意”按钮的实现
- 关于音箱的鉴别与选择
- 随感
- 《一级戒备》,漏洞百出的YY小品
- 把页面内容作为Email发出
- 十五位的身份证号转为十八位的(c#)
- 用 Preferences API 存储对象