1
function disableLbtSend() {
  document.getElementById('<%=Buttonclick.ClientID%>').disabled= true;
}
window.onbeforeunload = disableOgSend;  

I want to disable button after one click and has written the above code for it.It's working fine in IE but not in chrome and Mozilla. What should be done to get the desired solution

Pablo Salcedo T.
  • 705
  • 1
  • 15
  • 25
  • You could use jQuery as it will abstract the Browser specifics for you. Hopefully. – Wexoni Jun 19 '17 at 09:02
  • 1
    Possible duplicate of [How to disable html button using JavaScript?](https://stackoverflow.com/questions/3014649/how-to-disable-html-button-using-javascript) – VDWWD Jun 19 '17 at 09:02

3 Answers3

1

try this using jquery:

function disableLbtSend() { 
    $('#' + '<%= Buttonclick.ClientID %>').attr("disabled", "disabled");
}
brijrajsinh
  • 443
  • 3
  • 10
0

You can add a click handler to the button which removes itself after being triggered:

function clickOnceHandler(e) {
  // Do something.
  alert('Do something then disable the button');

  // Disable your button.
  e.target.disabled = true;

  // Remove this click handler.
  e.target.removeEventListener(e.type, clickOnceHandler);
}

const buttons = document.querySelectorAll('button');

for (let i = 0; i < buttons.length; i++) {
  buttons[i].addEventListener('click', clickOnceHandler);
}

function clickOnceHandler(e) {
  // Do something.
  alert('Do something then disable the button');

  // Disable your button.
  e.target.disabled = true;

  // Remove this click handler.
  e.target.removeEventListener(e.type, clickOnceHandler);
}
<button type="button">Click Once</button>
<button type="button">Click Once</button>
<button type="button">Click Once</button>
dork
  • 3,438
  • 2
  • 20
  • 46
0

try user jquery

function disableLbtSend() {
  $('#' + '<%= Buttonclick.ClientID %>').prop('disabled', true);
}
Tran Audi
  • 539
  • 6
  • 19