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

Hi,
   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..
gautam_reddycAsked:
Who is Participating?
 
Todd GerbertConnect With a Mentor IT ConsultantCommented:
You're using an <asp:Button>?  Set a "window.open()..." 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

	private void pdfButton_Click(object sender, EventArgs e)
	{
		openPdf = "true";
	}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
	<script language="javascript" type="text/javascript">
		function OnLoad() {
			if ("<%=openPdf %>" == "true")
				window.open("http://www.google.com");
		}
	</script>
</head>
<body onload="OnLoad()">
    <form id="form1" runat="server">
		<asp:Button ID="pdfButton" runat="server" Text="Open PDF" OnClick="pdfButton_Click" />
    </form>
</body>
</html>

Open in new window

0
 
Todd GerbertIT ConsultantCommented:
Make the target of the link "_blank"
0
 
gautam_reddycAuthor Commented:
its not the hyperlink.. we cannot open pdf in another winow using target="_blank".. thanks for trying though
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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?
0
 
gautam_reddycAuthor Commented:
thanks a ton..
0
 
Todd GerbertIT ConsultantCommented:
Glad to help, maybe next time I'll actually read your question before answering. ;)
0
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.