我有一个表单,它在单击提交按钮时在 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()";
这篇关于多个提交按钮点击问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!