Showing posts with label disable button after submit. Show all posts
Showing posts with label disable button after submit. Show all posts

Monday, May 6, 2019

Preventing multiple button clicks

There are scenarios when we need to disable a button to prevent multiple form submits. There can be many other ways, but following one tested and working for me.
Even though it is a kind of hack, it the easy way to achieve what needs to be happened

HTML

<asp:Button ID="btnSave" class="btn btn-sm" runat="server" Text="Save"  OnClientClick="DisableBtn(this);"  UseSubmitBehavior="false" />

JavaScript

<script type="text/javascript">

 function DisableBtn(btn) {
    btn.setAttribute('disabled', 'disabled');
   
    btn.click();

  }

</script >

Regards,
Samitha