Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net Control Button PostBack is causing redirection, when I don't want it to at all (print button)

Tags:

c#

asp.net

itext

here's how my scenario is created.

I click a button which produces a pdf via iTextSharp.

I then click 'Cancel' on the pop-up dialog.

I navigate to another page via hyperlink.

I then click the 'Back' button on IE8

I then click the button which produces the PDF, then I'm redirected to the page I previously viewed (when I clicked the hyperlink). Which is not intended what so ever.

Here's some code that affects the Response object (code is within print_click event)

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=ManageWorkforce.pdf");
Response.End();

Anyone have a theory why this is happening?

like image 574
Since_2008 Avatar asked Jan 29 '26 13:01

Since_2008


1 Answers

I have always done this with a generic handler like Greg mentioned. This is also nicer if you want to link to the file from other pages in the future, or save it as a favorite, send it to your friend, etc.

like image 129
flush96 Avatar answered Jan 31 '26 05:01

flush96



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!