Multiple submit Button click problem?(多个提交按钮点击问题?)
问题描述
我有一个表单,它在单击提交按钮时在 DB 中插入数据,但问题是当客户端多次单击按钮时,它发送多个创建请求意味着同一数据的同一时间有多个按钮单击事件,但不能这样.
I have a form which inserts data in DB on Submit button click but the problem is when client click the button multiple times its sends multiple create requests means multiple button click events for the same time of same data, which must not be.
当客户端第一次单击提交按钮时,我尝试禁用该按钮,但此后它不会调用服务器单击事件处理程序,也不会在禁用后触发服务器单击事件.
I tried to disable the button when client click the Submit button first time but after this it does not call server click event handler or not fire the server click event once it got disabled.
如何处理这个多次点击问题..
How to handle this multiple click problem..
我使用以下代码禁用按钮
I used the following code to disable the button
<script type="text/javascript">
function checkAuth(obj)
{
if(Page_ClientValidate("ValidationGroupName"))
obj.disabled=true;
}
</script>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_click" OnClientClick="checkAuth(this)" CssClass="FormButton"
ValidationGroup="ValidationGroupName" />
推荐答案
不要禁用按钮,只是防止第二次提交.
Do not disable the button, just prevent the second submit.
这个小脚本可以完成这项工作,但它假设在某个时刻有回发.
this little script does the job but it assumes there is a postback at a certain moment.
var formhandler = function() {
var submit, isSubmit = false;
submit = function(){
// flop and return false once by the use of operator order.
return isSubmit != (isSubmit = true);
};
return {
submit: submit
};
}(); // <-- use direct invcation to keep the internal variables "static"
附上:
document.forms[0].onsubmit = formhandler.submit;
或
OnClientClick = "formhandler.submit()";
这篇关于多个提交按钮点击问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:多个提交按钮点击问题?


基础教程推荐
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 如果条件可以为空 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 将数据集转换为列表 2022-01-01