Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am looking for a code to open pdf file new new tab.. my code is

pdfFileName = fetchData.PostGatepass(txtEntryNo.Text);
C#
Response.ContentType = "application/pdf";
Response.TransmitFile(pdfFileName);


here, pdfFileName returns the file and in doing so.. pdf file is opened in the same browser.. i dont want to use Response.AppendHeader bcoz it asks me to save or open.. i also dont want to user a href and set target = blank bcoz it required me to set a link. what i wanted is on click of button, file should open on new tab.. any help.. thanks in advance
Posted

1 solution

Try to open new tab on button click .. for this refer this link
After that on the page load event of newly opened page, do your operations for opening pdf(in same page from which function is executed)
 
Share this answer
 
Comments
Codes DeCodes 31-Jan-14 1:18am    
this is my code to open in new tab;
string address = "PdfReport.aspx";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "page_index_script", "window.open('" + address + "');", true);

it did not worked... i could not understand what is problem.
V5709 31-Jan-14 2:26am    
Use this..
----------------

ClientScript.RegisterClientScriptBlock(Page.GetType(), null, "window.open('About.aspx', '_newtab')", true);

-------------------------
Codes DeCodes 31-Jan-14 3:58am    
i tried ur code. it is not working i tried another code for opening openPdfReport.aspx page ..
ClientScript.RegisterClientScriptBlock(Page.GetType(), null, "window.open('PdfReport.aspx', '_blank');", true);
its not working too ... but one this works on client side page:OnClientClick="window.open('PdfReport.aspx', '_blank');"
i am totally confused now..
V5709 31-Jan-14 5:09am    
Check popups are enabled or not for browser.It worked for me,before giving i tested it.
If not worked then,use anchor tag or hyper link .If you don't want to specify pdf page url in design,then make link as server control by adding 'runat="server"' attribute. Now you will be able to specify redirection url from code behind, like on page load event by accessing that control
Codes DeCodes 31-Jan-14 5:21am    
thanks for the idea .. anyway i used ClientScript.RegisterStartupScript and now its working..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900