LinkButton not doing postback on second click

I want the clients to be able to download a PDF file. So I've put on a LinkButton with the code:


<asp:LinkButton ID="lnkPrintHere" runat="server" OnClick="lnkPrintHere_Click" Text="Click here" />

Code behind:

protected void lnkPrintHere_Click(object sender, EventArgs e)
    Response.ContentType = "application/pdf";
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
    Response.TransmitFile("/_layouts/Files/" + fileName);

Everything works fine the first time the link is clicked. Subsequent clicks don't raise the OnClick event. Has anyone any idea why this might be happening?

PS: Should you need more info, please feel free to ask.


This happens if you use Response.End()

This is mentioned here : Post Back does not work after writing files to response in ASP.NET

One workaround is to use a query string approach. When you click linkbutton redirect to same page with query string. And in page load, if you detect query string, emit the PDF and return.

You can always try alternatives in the response method itself, I used your code with Response.Close and its working fine. But I know, this is not the right option , but using query string for download is not a right option too.

Need Your Help

What would be the best way to go about writing this in JS/jQuery? (Multiple individual objects with multiple fields)

php javascript jquery optimization refactoring

Warning: This is a long read as there is a lot of information pertaining to the problem in question, so prepare yourself, and thanks for taking the time to go through this if you do!

PHP validation not working, overuled by form action

php javascript forms validation

I'm trying to use my PHP form validation on quiz.php, but my code takes me straight to result.php without checking for empty fields..

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.