Open PDF in the New window using C# in ASP.NET application

   i am trying to open a pdf document from the server.. when i click the button it opens the PDF in the web page.. i need to open it in the New window.. can anyone share the C# code.. thanks..
Who is Participating?
Todd GerbertConnect With a Mentor IT ConsultantCommented:
You're using an <asp:Button>?  Set a "" in the OnClientClick, or set a variable in code-behind to fire a client-side script.
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
	private string openPdf = String.Empty;

	private void pdfButton_Click(object sender, EventArgs e)
		openPdf = "true";

<html xmlns="">
<head runat="server">
	<script language="javascript" type="text/javascript">
		function OnLoad() {
			if ("<%=openPdf %>" == "true")"");
<body onload="OnLoad()">
    <form id="form1" runat="server">
		<asp:Button ID="pdfButton" runat="server" Text="Open PDF" OnClick="pdfButton_Click" />

Open in new window

Todd GerbertIT ConsultantCommented:
Make the target of the link "_blank"
gautam_reddycAuthor Commented:
its not the hyperlink.. we cannot open pdf in another winow using target="_blank".. thanks for trying though
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Todd GerbertIT ConsultantCommented:
You need to be much more specific with your question then. Is this an ASP.Net, WPF, or WinForms? How are you opening the PDF now? Can you post your code?
gautam_reddycAuthor Commented:
thanks a ton..
Todd GerbertIT ConsultantCommented:
Glad to help, maybe next time I'll actually read your question before answering. ;)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.