articles:

button click event firing twice

We recently had several button controls that were consistently firing twice on click. After a fair amount of head scratching and feeling stupid, it turns out that we were handling the button click twice - not really surprising that the event was firing twice then.

The reason the click was being handled twice was because the onclick handler was being specified twice: once in the button tag as the OnClick attribute:

<asp:Button ID="myButton" runat="server" Text="my button" OnClick="myButton_Click" />

and once in the code behind

Protected Sub myButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles myButton.Click

Simply removing the OnClick attribute from the button tag solved this problem.

Comments

There are no comments on this article yet, be the first to leave one

Post a comment

name:
(optional)

email:
(optional)

comment:

call us on 01344 762988