Multiple submit Button click problem?

南楼画角 提交于 2019-11-29 17:07:53

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()";

Include a unique id in a <input type="hidden"> field. Then on the server check if the request has already been processed.

As an ID you can generate a GUID. Then you just need some structure to collect currently valid IDs. For example a Dictionary. Then from time to time you can clear old IDs out of the structure, and of course remove it when it is used.

All you have to do is have some client side javascript which disables the button. Something similar to:

document.myform.mybutton.disabled  = true;

If you wrap this in a function, and set the onClientClick attribute of your button to fire this. As soon as it gets clicked it is disabled - but still generates the request to the server.

The reason the event didnt fire the way you suggested above is likely because you disabled server side (not client side as is here)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!