Disable a button on click

后端 未结 9 1516
栀梦
栀梦 2020-12-31 07:04

I have a button control. Once the user clicks on it, the click event should fire and then the button should get disabled. How can I do this? I have the option to use JQuery

相关标签:
9条回答
  • 2020-12-31 07:05

    you can disable it server side

    Button1.Enabled = false;
    
    0 讨论(0)
  • 2020-12-31 07:06

    add an OnClientClick="this.disabled = true;" to your button.

    If you are using Asp.net Ajax you might want to look at using PostBack Ritalin.

    0 讨论(0)
  • 2020-12-31 07:07
       <script type="text/javascript">
         Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
          function BeginRequestHandler(sender, args) {
            document.getElementById('<%= lblMessage.ClientID %>').innerText = "Processing...";
              document.getElementById('<%= btnSubmit.ClientID %>').innerText = "Processing";
             args.get_postBackElement().disabled = true;
               }
               </script>
    

    Add Script Tag in source page . change Id of button in code . You can disable the button till the process completes execution .

    0 讨论(0)
  • 2020-12-31 07:12

    There is really cool event for body tag "<"body onBeforeunload="buttonId.disabled = true;" ">"

    This event triggers right before form submits, in other words your data will be submitted correctly.

    0 讨论(0)
  • 2020-12-31 07:17

    When using the "this.disabled = true" method make sure you check if the page is valid before disabling the control if you have validators on the page. If validation fails you won't be able to re-enable the control without reloading the page.

    if (Page_IsValid) this.disabled = true;
    
    0 讨论(0)
  • 2020-12-31 07:23
    // to disable
    this.setAttribute('disabled', true); 
    // to enable
    this.removeAttribute('disabled');
    

    this is a cross browser solution

    0 讨论(0)
提交回复
热议问题