Search code examples
c#asp.netevent-handlingasplinkbutton

Click event Firing twice


I have the following LinkButton in my ASP.NET website:

<asp:LinkButton ID="btnUpload" runat="server" CssClass="btn btn-primary" OnClick="btnUpload_Click">
    <span aria-hidden="true" class="glyphicon glyphicon-upload"></span> Upload File
</asp:LinkButton>

When the user clicks it, it should get fired once only, but it's getting fired twice.

What could be the reason?


Solution

  • How does your codebehind look? Are you sure you don't have the event hooked up there as well?

    You have OnClick="btnUpload_Click" in your markup which would hook up the event handler once, so if you also have a btnUpload.Click += btnUpload_Click; in the codebehind, the event handler would fire twice.