Question

I'm using asp:LinkButton on my page and on click I download a file.But the issues is after I have clicked the download Link Button if I click any other button on the page, it repeats the download action. Can anyone throw some light about why this is happening.

Here is my linked button code

  protected void lnkBtn_Click(object sender, EventArgs e)
  {
        //Download code
  }
Was it helpful?

Solution

This can happens if you have an UpdatePanel somewhere in your page. UpdatePanel modify and remember the viewstate because is wait for replay from this click.

What you do is that you do not return what UpdatePanels waits, because you download a file as you say. So on the next click the UpdatePanel re-send the click because did not have get replay in the first place.

To solve that is better to not download the files with the post back, but with a handler and a link - here is an example: What is the best way to download file from server

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top