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
Norman Yuan - 10 Jan 2006 20:07 GMT
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).
> Thanks for your prompt reply Norman. I accidently posted to *.adonet
> rather than *.aspnet. I posted a retraction. I might get some new
[quoted text clipped - 42 lines]
> Response.Close()
> End Sub