Double click button

It seems that sometimes (but not always) my button click event fires twice. The fact that this happens sometimes, but not always, really puzzles me. Here is my button:

<button id="btnSave" onserverclick="btnAddUser_Click" name="btnSave" type="submit" style="font-size:11px;font-family:Verdana;font-weight:bold;" runat="server">Save</button> 
+11
source share
15 answers

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

+22
source share

I just stumbled upon the same problem and wanted to point out that removing "Handles btnSave.Click" from your event will not allow it to be called twice. For example, use this in the code behind:

 Protected Sub btnSave_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) 'Do Something End Sub 

Instead of this:

 Protected Sub _btnSave_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click 'Do Something End Sub 
+6
source share

Instead, use your own ASP.NET button.

 <asp:Button id="btnSave" runat="server" OnClick="btnAddUser_Click" style="font-size:11px;font-family:Verdana;font-weight:bold;" Text="Save" /> 
+2
source share

Looks like a problem with connecting event handlers. http://geekswithblogs.net/TimH/archive/2006/10/23/94874.aspx

Try it if you can just handle the events at your end. In addition, the problem may be related to type = "Submit". Check if this button has changed to a button only.

+2
source share

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

+2
source share

One possible reason:
Check your button declaration in .aspx source. If you have 'runat=server' and onclick="button1_click" , and you have an event handler in your code (ie. Aspx.vb), this will cause the event to be fired twice. Here is an example in xxx.aspx:

 <asp:Button id="button1" onclick="button1_Click" runat="server" Text="Click Me!"></asp:Button> 

This announcement should be:

 <asp:Button id="button1" runat="server" Text="Click Me!"></asp:Button> 

Good luck

+1
source share

The solution has already been mentioned in another answer. Use type = "button" instead of sending

Here is a sample code

  <span class="input-group-btn"> <button id="btnLoadCustomerFile" class="btn btn-default" type="button" runat="server" onserverclick="btnLoadCustomerFile_Click" >Load</button> </span> 

And the internal code for click-through processing

  protected void btnLoadCustomerFile_Click(object sender,EventArgs e) { LoadCustomerFile(); } 
+1
source share

The correct way (on the ASP.NET web form page), as already mentioned by the other two participants, is to add the type = "button" attribute to the element and associate a onserverclick event delegate handler.

For example:

 <button type="button" id="btnSave" runat="server" onserverclick="btnSave_ServerClick" class="btn btn-success btn-label"> <i class="fa fa-save"></i>Save </button> 

Hope this helps.

0
source share

I think I just decided to find a solution. Remove name="btnSave" or change it to "btnSave1" . He will work.

0
source share

I had the same problem, but a completely different reason. I set the defaultbutton property of the container bar for a button that is run twice. After removing the DefaultButton "property from Asp: Panel, the problem is resolved.

0
source share

I just had to go back to the old school ASPX and found this problem.

My form was configured as follows.

 <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" > 

Code 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 Panel and add

 TabIndex="4" 

at LinkButton.

0
source share

I had a similar problem. I used I changed it to did not work.

But when I changed it to it worked.

Thank you This post helped me.

0
source share

In my case, this happens to me when I use Chrome, but not in Firefox

0
source share

This is because the type of button is send. You need to change it to a button in order to resolve button events that fire twice. Refer to this blog for further explanation.

https://mzulkamal.com/blog/asp-net-web-form-html-button-tag-fires-two-times-s

0
source share

If you are using asp.net, just use asp: button ..... its clean and simple. No matter what excuse I read on the network, it makes no sense that a server-side handler should be called twice. When I add type = "button", the problem is resolved. However, the form is not submitted when I press the enter key. So another problem has to be solved. Using the asp button: takes care of all this.

-2
source share

All Articles