“To avoid duplicate credit card charges, only click the checkout button once!”

I’m always surprised at how many sites display a similar warning message on their final checkout page. Major sites. Between server side detection of multiple submissions and using OnClick to disable the submit button, there is no excuse for crossing your fingers and hoping your users don’t double click a submit button.

AJAX complicates the client side component of this equation. You can’t simply disable a button in the OnClick event, because the button will remain disabled in the case of a failed form validation or other exception. The optimal behavior is for the submit button to only be disabled during the async postback, and be re-enabled when the server side processing is completed. Using the AJAXToolKit, I’ve created a control extender to implement this functionality quickly and easily: Postback Ritalin.

Note: If you found this in an attempt to implement a similar effect for non-AJAX, full postbacks then take a look my Disable a button control during postback example instead.

Usage example

The TargetControlID specifies which UpdatePanel to watch. WaitText allows you to optionally provide text that is displayed in the disabled button while the async postback happens.

Download

Downloads have been moved to the permanent Postback Ritalin page.