Disable button instantly

advertisements

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


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.