For the project I’m currently working on, I needed to develop a WebPart which provides (among other functionality) a download link to a file stored in the database. I’ve used a LinkButton to render the download link and in it’s Click event I’m retrieving the file from the database and output it to the Response stream like this:
Page.Response.ClearContent();Page.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);Page.Response.ContentType = "application/pdf";Page.Response.AddHeader("Content-Disposition", "attachment; filename=document.pdf");Page.Response.Buffer = true;Page.Response.BinaryWrite(file);Page.Response.End();
Now, when a user clicks the download button, a File Dowload Dialog is displayed in the browser. When this dialog is closed the page is not responding to any click within the webpart’s content that normally would cause a postback to occur. With a little Googling, I found this thread which fully describes the cause of the problem and provides a neat solution.

