Daniel Klöck
Daniel Klöck

Reputation: 21137

Open Pdf in new tab

On Button Click I generate a PDF file and then open it at client side with:

Response.ContentType = "application/pdf";
Response.TransmitFile(path);

This will show the pdf in the browser, but in the same tab. How can I open it in a new tab?

Upvotes: 4

Views: 6963

Answers (2)

ravenik
ravenik

Reputation: 852

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script  language=vbscript>
sub OpenInNewWindow()
    window.open("PDFContainer.aspx")
end sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Way 3</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type=button OnClick="OpenInNewWindow()"  value="Open in New Window"/>
        <br /><br />
        This time, we will open a new Internet Explorer Window and Show the PDF File directly in the IE
    </div>
    </form>
</body>
</html>

Upvotes: 4

Johnno Nolan
Johnno Nolan

Reputation: 29659

You cannot do this from the server side. It is a client side operation. see Create a new tab or window for a web page from ASP.NET

Upvotes: 1

Related Questions