0

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?

khellang
  • 17,550
  • 6
  • 64
  • 84
Nuke
  • 1,169
  • 5
  • 16
  • 33

2 Answers2

7

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.

khellang
  • 17,550
  • 6
  • 64
  • 84
  • `Protected Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click` `End Sub` – Nuke Jul 01 '15 at 07:41
  • 2
    Exactly. See that `Handles btnUpload.Click`? That makes it handle the event twice. Either remove that, or the `OnClick="btnUpload_Click"`. – khellang Jul 01 '15 at 07:55
0

You can set the AutoEventWireup="false" here is example how to use it : https://support.microsoft.com/en-us/kb/324151

Nikolay
  • 329
  • 1
  • 7