多提交按钮点击的问题?多提、按钮、问题

2023-09-02 02:05:31 作者:一炮而红

我有插入数据的数据库上的提交按钮点击一个形式,但问题是当客户点击按钮多次其发出多个创建请求意味着多个按钮单击事件相同的数据,这不能是同一时间。

我试图禁用按钮时,客户端点击提交按钮第一次,但在此之后它不会调用服务器上单击事件处理程序或不会触发服务器click事件一旦得到禁止。

如何处理这种多重点击问题。

我用下面的code禁用按钮

 <脚本类型=文/ JavaScript的>
     功能checkAuth(OBJ)
     {
         如果(Page_ClientValidate(ValidationGroupName))
            obj.disabled = TRUE;
     }
 < / SCRIPT>

        < ASP:按钮的ID =btnSubmit按钮=服务器文本=提交
的OnClick =btnSubmit_click的OnClientClick =checkAuth(本)的CssClass =FormButton
ValidationGroup =ValidationGroupName/>
 

解决方案

不要禁用按钮,只需prevent第二次提交。

这个小脚本执行的工作,但它假定有一个回发在某一时刻。

  VAR formhandler =功能(){
   VAR提交,isSubmit = FALSE;
   提交=功能(){
                //翻牌以及通过使用运营商为了返回false一次。
    !返回isSubmit =(isSubmit = TRUE);
    };
    返回 {
       提交:提交
    };
}(); //<  - 使用直接invcation保持内部变量静态
 

通过附加的:

  document.forms [0] .onsubmit = formhandler.submit;
 
element ui 防止多次触发按钮单击事件 或防止多次提交数据

 的OnClientClick =formhandler.submit();
 

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"

attach it by :

   document.forms[0].onsubmit = formhandler.submit;    

or

   OnClientClick = "formhandler.submit()";