1

I have couple of asp.net link buttons, can't change them to asp.net hyperlinks. I want to open a pdf file when buttons are clicked while pdf files are located on a different server (example http://www.targetserver.com/sample.pdf) from http://www.sourceserver.com where link buttons are. Want to open pdfs in the same window. Can I use Response.Redirect somehow passing in pdf url which opens pdf in the same window?

3

4 Answers 4

1

Yes, a response redirect will work just fine as long as you pass the fully qualified URL.

Response.Redirect("http://www.site.com/target.pdf");

Should redirect the browser to the PDF file.

Response.Redirect works by sending the browser an HTTP 302 so the target can be on the same server or another server.

2
  • Thanks Frazell, can you please let me know how to pass the fully qualified url, I am struggling making it fully qualified.
    – Nexus23
    Aug 28, 2012 at 13:57
  • Added a sample and link to documentation to explain Response.Redirect. Aug 28, 2012 at 15:06
1

You can use Response.Redirect like this:

Response.Redirect("http://www.targetserver.com/sample.pdf");
0
0

Try this:

protected void LinkButton1_Click(object sender, EventArgs e)
{
   Response.Redirect("http://www.targetserver.com/sample.pdf");
}
0

I have tried, Response.Redirect("targetserver.com/sample.pdf";) but it navigates like this sourceserver.com/www.targetserver.com/sample.pdf

Of course, because if you don't specify the protocol, it assumes you're referring to some file located on the server. You need to append http:// in this case.

Furthermore, the action "what happens" depends on user's client. If the client doesn't have Adobe Reader installed or has set his browser to save files instead of opening them, it obviously won't open. If you want to be sure that the file gets opened in the browser, you need to implement some pdf reader on your website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.