Preventing accidental double clicking on a button

See this example for disabling control on postback. It should help you do what you're trying to achieve.

http://encosia.com/2007/04/17/disable-a-button-control-during-postback/


You don't necessarily want to show the button disabled on postback. You want to make sure they don't accidentally submit twice. So disabling or hiding the button as a result of a server-side action is already too late in the game. By this point the 2nd request is already on it's way. You need to either do it with javascript or make sure your server side code won't run twice.


In case of an updatepanel and a button inside a FormView-Template I use the following approach:

<script type="text/javascript">
    // Using that prm reference, hook _initializeRequest
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequestBuchung);

    // Abfangen von Mehrfachklicks auf Buttons für asynchrone Postbacks im Updatepanel
    function InitializeRequestBuchung(sender, args) {
        var arrButtonIds = ["ButtonInsert", "ButtonUpdate"];

        // Get a reference to the PageRequestManager.
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        if (prm.get_isInAsyncPostBack() & jQuery.inArray(args.get_postBackElement().id, arrButtonIds) > -1) {
            args.set_cancel(true);
        }
    }
</script>

This cancels a following postback if currently a async postback is still active. Works perfectly.