|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
open new page when download PDF/helpthat works. So I'm asking again. I am using .Net 1.1 on a Windows XP Pro. What I want is for the browser to display a PDF "inline" in the browser in a "new" window. The PDF comes from a database and I stream it to the browser. The key points are "inline" and "new window". My code works but it displays the PDF in the current window. Here is an example. This code is executed on a button click on the server. When I remove the comments, the browser displays junk. I would like it to display my document in a new window. Any ideas on how I can get this to work? Thank you Barry ' Response.BufferOutput = True ' Response.ClearHeaders() ' Response.ClearContent() ' Response.ContentType = "text/plain" ' Response.AddHeader("Content-Type", "text/plain") ' Response.Write("<script language=""javascript"">window.open()</script>") Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "inline; filename=cv.pdf") Response.AddHeader("Content-Type", "application/pdf") Response.WriteFile(myCV.ToString()) Response.Flush() Response.Close() Oops, I posted to the wrong group.
I have reposted to microsoft.public.dotnet.aspnet Barry Server side code is not allowed to open new browser window (otherwise client
computer would be flooded by endless popups and become useless). You need explicitly open a new window with client side code and then send request to the PDF page from there. Say, you have a button, on its "onclick" event, you add javascript like this: var win=window.open("MyGetPDFPage.aspx?PDFID=xxx","PDFWindow"); win.focus(); <bbulsar***@hotmail.com> wrote in message Show quote news:1136898928.865427.215480@g49g2000cwa.googlegroups.com... > Hi, this has been asked so many times before but I cannot get an answer > that works. > > So I'm asking again. > > I am using .Net 1.1 on a Windows XP Pro. > > What I want is for the browser to display a PDF "inline" in the browser > in a "new" window. The PDF comes from a database and I stream it to the > browser. The key points are "inline" and "new window". My code works > but it displays the PDF in the current window. > > Here is an example. This code is executed on a button click on the > server. When I remove the comments, the browser displays junk. I would > like it to display my document in a new window. Any ideas on how I can > get this to work? > > Thank you > Barry > > > ' Response.BufferOutput = True > ' Response.ClearHeaders() > ' Response.ClearContent() > ' Response.ContentType = "text/plain" > ' Response.AddHeader("Content-Type", "text/plain") > ' Response.Write("<script > language=""javascript"">window.open()</script>") > > Response.ContentType = "application/pdf" > Response.AddHeader("content-disposition", "inline; filename=cv.pdf") > Response.AddHeader("Content-Type", "application/pdf") > Response.WriteFile(myCV.ToString()) > Response.Flush() > Response.Close() > Thanks for your prompt reply Norman. I accidently posted to *.adonet
rather than *.aspnet. I posted a retraction. I might get some new glasses. I still don't understand though. I have posted bits of my Page_Load and button click procedures. Where exactly do I add your Javascript to open the new window for each document. Your code is below. > var win=window.open("MyGetPDFPage.aspx?PDFID=xxx","PDFWindow"); Here is my code for "WebForm2.aspx". As it is now it works and> win.focus(); retrieves 11 (although the number changes) documents from an Access database. It displays 11 buttons on the page. When I click on the 4th button, I get the 4th document as a PDF in the same browser window. I would like this to be in a new browser window. Thank you for your patience. Barry Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim b As Button Dim i as Integer For i As 0 To getCVCount() - 1 b=New Button() b.Text=BUTTONNAMES(i) Session.Add("cv" + b.GetHashCode.ToString(),getCVfromDB(i)) AddHandler b.Click, AddressOf buttonClick Next i End Sub Private Sub buttonClick(ByVal sender As Object, ByVal e As System.EventArgs) Dim myCV As Object myCV=Session.Item("cv"+sender.GetHashCode().ToString()); Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "inline; filename=cv.pdf") Response.AddHeader("Content-Type", "application/pdf") Response.WriteFile(myCV.ToString()) Response.Flush() Response.Close() End Sub As I mentioned in previous reply, you cannot open new window from server
side. So your logic of work would be to write two (or more) .aspx page. The first page would provide 11 buttons which would all have client side javascript code attached that opens new browser window. This page does not post back to get the PDF (or other files you are to stream back to client). So, in the first page, you may have code like this (C#): private void Page_Load(....) { if (!Page.IsPostBack) { //Attach client side code to the button(s), so clicking it would open a new window btnPDF.Attributes.Add("onclick","OpenNewWindow('PDF');return false;"); btnDOC.Attributes.Add("onclick","OpenNewWindow('DOC');return false;"); } } Then in the page's HTML view, add following javascript to <Header> section <Script Language="javascript"> function OpenNewWindow(fileType) { var win; switch(fileType) { case "PDF" win=window.open("GetPDF.aspx","NewWindow"); break; case "DOC" win=window.open("GetDOC.aspx","NewWindow"); break; ....... } win.focus(); } </Script> You can see here, you may have one or more aspx pages that is opened in new window and requests the pdf (or other files). <bbulsar***@hotmail.com> wrote in message Show quote news:1136904777.698791.219540@z14g2000cwz.googlegroups.com... > Thanks for your prompt reply Norman. I accidently posted to *.adonet > rather than *.aspnet. I posted a retraction. I might get some new > glasses. > > I still don't understand though. I have posted bits of my Page_Load and > button click procedures. Where exactly do I add your Javascript to open > the new window for each document. > > Your code is below. > >> var win=window.open("MyGetPDFPage.aspx?PDFID=xxx","PDFWindow"); >> win.focus(); > > > > Here is my code for "WebForm2.aspx". As it is now it works and > retrieves 11 (although the number changes) documents from an Access > database. It displays 11 buttons on the page. When I click on the 4th > button, I get the 4th document as a PDF in the same browser window. I > would like this to be in a new browser window. > > Thank you for your patience. > > Barry > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > Dim b As Button > Dim i as Integer > For i As 0 To getCVCount() - 1 > b=New Button() > b.Text=BUTTONNAMES(i) > Session.Add("cv" + b.GetHashCode.ToString(),getCVfromDB(i)) > AddHandler b.Click, AddressOf buttonClick > Next i > End Sub > > > > > Private Sub buttonClick(ByVal sender As Object, ByVal e As > System.EventArgs) > Dim myCV As Object > myCV=Session.Item("cv"+sender.GetHashCode().ToString()); > Response.ContentType = "application/pdf" > Response.AddHeader("content-disposition", "inline; filename=cv.pdf") > Response.AddHeader("Content-Type", "application/pdf") > Response.WriteFile(myCV.ToString()) > Response.Flush() > Response.Close() > End Sub > |
|||||||||||||||||||||||