button firing click event twice

后端 未结 14 2103
忘了有多久
忘了有多久 2021-02-07 21:28

It seems that sometimes (but not always) my button click event is being fired twice. The fact that it seems to happen sometimes but not always is really puzzling me. Here is m

相关标签:
14条回答
  • 2021-02-07 22:06

    Use a native ASP.NET button instead.

    <asp:Button id="btnSave" runat="server" OnClick="btnAddUser_Click"  
         style="font-size:11px;font-family:Verdana;font-weight:bold;" Text="Save" />
    
    0 讨论(0)
  • 2021-02-07 22:08

    I had the same problem, and it took me a while to figure it out! If you add type="button" to your button, it seems to fix the issue.

    0 讨论(0)
  • 2021-02-07 22:09

    Just had to delve back into old school ASPX again and found this issue.

    My form was set up like this.

    <asp:UpdatePanel ID="login" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Panel ID="forgotPassword" runat="server" DefaultButton="lbtnSendLoginDetails" Visible="False">
                <asp:LinkButton ID="lbtnSendLoginDetails" runat="server" >
    

    The code behind was

    Protected Sub lbtnSendLoginDetails_Click(sender As Object, e As EventArgs) Handles lbtnSendLoginDetails.Click
    

    The answer for me was to remove the DefaultButton attribute from the Panel and add

    TabIndex="4" 
    

    to the LinkButton.

    0 讨论(0)
  • 2021-02-07 22:10

    If you are using code behind, don't use OnClick in ASP tag, <button id="btnSave" name="btnSave" type="submit" style="font-size:11px;font-family:Verdana;font-weight:bold;" runat="server">Save</button>

    0 讨论(0)
  • 2021-02-07 22:12

    In my case, It happens to me when I use Chrome, But not in Firefox

    0 讨论(0)
  • 2021-02-07 22:16

    Looks like the problem with wiring up of event handlers. http://geekswithblogs.net/TimH/archive/2006/10/23/94874.aspx

    Try if you can just have event handler in your back end. Also, the problem could be because of the type = "Submit". Check if changing it to just Button fixes the problem.

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