Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instantly disable Button on click

I'd like to instantly disable a Button after clicking it, so a User can't click it twice in short succession and fire the OnClick_Event twice in a row. btn.Enabled = false doesn't seem to do the trick instantly. Is there any other way to accomplish this?

Thanks,

Dennis

like image 965
Dennis Röttger Avatar asked Dec 10 '22 09:12

Dennis Röttger


1 Answers

What you are doing is disabling it after a post back therefore your button will be disabled in the page that's rendered when the browser receives the response.

Do it on the client-side with JavaScript instead:

var button = document.getElementById('yourButton');
button.disabled = true;

If you're facing issues with posting back to the server, check out this article: How to disable an ASP.NET button when clicked.

like image 156
Andreas Grech Avatar answered Dec 11 '22 21:12

Andreas Grech