HtmlButton handler fires twice when clicked (when AutoEventWireup=“True”)

I have an html button, see below. When it's clicked and AutoEventWireup="true", the Save_Click click handler is fired twice. When AutoEventWireup="False", it fires once.

Why is it firing twice? The button is not registered twice and no code which is adding the event handler. Using master page and no Ajax.

<button id="Save" accesskey="v" type="submit" runat="server" onserverclick="Save_Click"></button>
13.10.2009 19:58:24
there must be something else in the code causing it to fire, I think we'd need to see all the associated code for the page. It is very unlikely that the button is doing it on it's own.
kscott 13.10.2009 20:13:06
3 ОТВЕТА

Just a guess: the handler isn't being fired twice, but you've set up a similar behavior in the Page_Load event that makes it appear to be firing twice.

0
13.10.2009 20:05:03
The breakpoint inside the handler is hit twice before the page returns. The handler inserts a record in a table and I see two records. There's no other place in the code with an insert and there are no database triggers.
Tony_Henrich 13.10.2009 20:08:51
РЕШЕНИЕ

Ok I found out that that an HTMLButton fires for the onserverclick event and for the type="submit". When I removed type="submit", it fires once. This quirky behavior took me a long time to discover!

14
13.10.2009 23:15:55
In my case I hadn't told it use type="submit", I just hadn't specified a type. I explicitly specified type="button" and it was fixed after that.
Peter 3.05.2013 13:33:57
This has interestingly different behavior based on which ASP.NET version you're running or which browser you're using. Example, I didn't specify type and it works fine on Fireofox, but Chrome assumed it was a submit instead of button
But I'm Not A Wrapper Class 5.02.2015 16:06:13

And now (at least in .net 4) even better:

<button runat="server">

by default behaves as it has type="submit" (fires twice on click), so for it to work correctly, we should explicitly set type="button", i.e.:

<button id="ButtonSubscribe2" runat="server" type="button" onserverclick="Save_Click"></button>
28
11.02.2013 17:29:45
Solved my problem. Thanks!
jmotes 21.01.2014 17:53:05
I had to work around this inside some procedures.... Never new it was this what was causing the issue. Many thanks!
Hector Diaz 12.09.2017 00:55:44