Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  




           


Prevent double click of ASP.NET Button or ImageButton
To prevent a double click of a .NET Button or ImageButton (which sends the page to the server multiple times - very bad), you can add javascript to the button, which makes the button invisible the first time it is clicked. You should simultaneously set another control Visible that explains what happened to the button. For example, a label with text 'Please wait while your changes are saved'.
The button will reappear after the postback.

Your javascript should NOT make the button invisible if the button CausesValidation (default), but the page is invalid - as this will make the button disappear, even though the page fails to submit.
The following must return true, unless your button has CausesValidation == false:
window.Page_ClientValidate == undefined || Page_ClientValidate()

If the button is in an update panel in IE11 with Compatibility mode off, this does not work, because the button is rerendered before the update completes, allowing user to double click.
However, you can set button.UseSubmitBehavior = false. This forces button to not rerender until the post back has completed, allowing the above fix to work regardless of whether button is in an update panel.

Created By: amos 3/19/2013 6:16:03 PM
Updated: 1/13/2014 5:03:39 PM


 Comments:
 > Guest 8/14/2014 2:03:19 PM
ImageButton does not have a UseSubmitBehavior does it?