How to disable submit button once it has been clicked?

后端 未结 18 1557
轻奢々
轻奢々 2020-12-01 05:06

I have a submit button at the end of the form.

I have added the following condition to the submit button:

onClick=\"this.disabled=true;
this.value=\'         


        
18条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 05:35

    In this working example, the user confirms in JavaScript that he really wants to abort. If true, the button is disabled to prevent double click and then the code behind which updates the database will run.

    
    

    I had issues because .net can change the name of the button

    function abort() {
        if (confirm('')) {
            var btn = document.getElementById('btnAbort');
            btn.disabled = true;
            btn.innerText = 'Aborting...'
            return true;
        }
        else {
            return false;
        }  
    }
    

    Because you are overriding the OnClick with OnClientClick, even if your validation method succeeds, the code behind wont work. That's why you set UseSubmitBehavior to false to make it work

    PS: You don't need the OnClick if your code is in vb.net!

提交回复
热议问题