Html button handler fires twice on ServerClick


Problem:

There is a scenario where a "button" HTML element may fire two ServerClick events off. In the old days, this usually meant that the button had AutoEventWireup set and was also manually being set (thus wiring in twice). That is not the case in this scenario.

Solution:

In this case, the button element also needs to have it's type set to "submit" instead of "button" and this may cause the behavior of firing twice. Trying switching the property and see if it fixes the issue.

Correct ASP.NET Markup

<button id="btnSave" type="button" runat="server" onserverclick="btnSave_Click">

Incorrect ASP.NET Markup

<button id="btnSave" type="submit" runat="server" onserverclick="btnSave_Click">

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.