Preventing accidental double clicking on a button

后端 未结 7 950
夕颜
夕颜 2020-12-18 03:11

I have a few controls that inherit from ASP.NET buttons and use onserverclick.

If the user clicks twice, the button fires two server side e

相关标签:
7条回答
  • 2020-12-18 03:25

    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.

    0 讨论(0)
  • 2020-12-18 03:25

    Instead of hiding, what I have done is swapping buttons using javascript. Show another greyed out image on the click of the first button.

    0 讨论(0)
  • 2020-12-18 03:33

    You can also try for example btnSave.Enable = false; when the button is hit and before the processing for the button is done in the Click Event routine. If you need it to be reset to allow it to be enabled have a separate button that resets the button for reuse.

    Another method is to set the button with verification so that the user is asked if they want to Save, it should pop up both times.

    Yet another method would be to flag the first occurrence then set a popup for the second to verify a second or subsequent usage.

    0 讨论(0)
  • 2020-12-18 03:36

    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/

    0 讨论(0)
  • 2020-12-18 03:37

    Set the Button property UseSubmitBehavior to false. Then create an OnClientClick function that disables the button. It would look something like this:

    <script type="text/javascript">
       function disableFunctn(button){
           button.disabled = true;
       }
    </script>
    <asp:Button ID="button1" UseSubmitBehavior="false" OnClientClick="disableFunctn(this);"/>
    

    fastest cheapest way:

    <asp:Button ID="button1" UseSubmitBehavior="false" OnClientClick="this.disabled=true;"/>
    
    0 讨论(0)
  • 2020-12-18 03:42

    Someone else said this somewhere on here a few days ago, and I concur - use javascript to simply hide the button instead of disabling it; you could show a "spinner" image in its place, which lets the user know what is going on.

    0 讨论(0)
提交回复
热议问题