[RESOLVED] how to open a pdf file in a new window

Hi, I have a button that once clicked it open a pdf file in the same window. I need to be able to open in a new window

How can I open this pdf in a new window.

        protected void btnPrint_Click(object sender, EventArgs e)
        {    // generate pdf file
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("ID", txtID.Text);
            aslBL.Reporting rpt = new Reporting(xxx, xxx, xxx);
            byte[] ret = rpt.Render(System.Configuration.ConfigurationSettings.AppSettings["reportName"], Reporting.Format.PDF, d);
            if (!ret.Length.Equals(0))
            {
                Response.Expires = 0;
                Response.Buffer = true;
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", "inline; filename=myReport.pdf");
                Response.AddHeader("Content-Length", ret.Length.ToString());
                Response.BinaryWrite(ret);
            }
        }

 

The reason for my request is that before a user click on print report, a user click on a button to make some of the controls on the page grayed out - enabled = false; so when a user click on print report, a pdf document open BUT once he click on return back in the browser, all the controls that were grayed out are back. so how to fix this issue. i thought to open a new window for the pdf.

If you have a better solution, please share it with me.

Thanks

 

Bob

Your description is not fully clear to me about pressing a control to disable some cotnrol and then press a button to open PDF!

But based on my understaing you can try these options:

1. Create a seperate aspx page something like showpdf.aspx, which contains the same code as on button click but on page_load, you can pass parameter to this page in querystring or session, whatever suits your situation. OnClientClick of Button you can call window.open function in javascript, that will launch showpdf.aspx and display pdf.

2. another options is, if you need to do some data processing etc. then you can use button click and then then use Page.RegisterClientScript or Page.RegisterStartipScript function to launch showpdf.aspx.

I hope this helps. you can find lots of example on javascript:window.open('pagename','options'); or how to use Page.RegisterStartupScript() function.

In the html part of that button "btnPrint" please add this.

OnClientClick="aspnetForm.target ='_blank';"

Hi and thanks for your prompt response. I tried this code and did not work. I am not sure if I understood what you ment by aspnetForm .I  assumed it i sthe aspx page to be opened... please advise.........thanks bob

 

 

<asp:Button ID="btnOpenNewWindow" runat="server" Text="Open new window"

 

OnClientClick

="Target.aspx.target ='_blank';"/>

<div style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; width: 100%; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;">

HI,

open new window on ur btnprint

OnClientClick="window.open('showPdf.aspx','','menubar=no,resizable=yes,scrollbars=yes');"

and in showpdf.aspx page load write ur code (which is written on print button)

u can pass paramater in showpdf page in case it required...

</div>

Thanks for your reply,

Is there a way that I can control all different attributes of the open window. for instance. I want to have a full control of the new open window so I can show/ hide the back button, and other items in the opened window.... thanks (:

Bob

thanks it worked

thoughts on "[RESOLVED] how to open a pdf file in a new window"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>