How do I launch a new window in ASP.NET

G

Guest

I have several web apps that I want to redirect to a new page, but have that page open in a new browser window. The basic scenario is that I have a CrystalReport object that gets created and displayed on-screen as a .PDF stream. I need to have this page launch in it's own window leaving the first browser alone

Here's the code I'm using to launch the report

Private Sub btnPrintList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintList.Clic
'Set up and fill the DataSe
Me.DsCalendar1.calMonthlyItems.Clear(
Me.daMonthlyItems.SelectCommand.Parameters("@tStartDate").Value = Me.Calendar1.VisibleDat
Me.daMonthlyItems.SelectCommand.Parameters("@tEndDate").Value = Me.Calendar1.VisibleDate.AddMonths(1).AddDays(-1
Me.daMonthlyItems.Fill(Me.DsCalendar1
'Populate and create the repor
Dim crReport As New EventLis
crReport.SetDataSource(DsCalendar1
'Convert the report to a PDF strea
Dim strStream As New System.IO.BinaryReader(crReport.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat)
'Display the PDF content in the browser. Here's where I'd like the system to launch a new browser
Response.ClearContent(
Response.ClearHeaders(
Response.ContentType = "application/pdf
Response.BinaryWrite(strStream.ReadBytes(strStream.BaseStream.Length)
Response.Flush(
Response.Close(
End Su

Thanks
 
K

Kevin Spencer

The only way to launch a new browser window is on the client side, using
JavaScript's window.open() method (well, you can do it with a link and a
target frame, but you have much less control, but in either case you have to
do it on the client, not on the server). What you can do on the server is to
dynamically create the script to open the new window and add it to the Page
using RegisterStartupScript().

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Jacob said:
I have several web apps that I want to redirect to a new page, but have
that page open in a new browser window. The basic scenario is that I have a
CrystalReport object that gets created and displayed on-screen as a .PDF
stream. I need to have this page launch in it's own window leaving the
first browser alone.
Here's the code I'm using to launch the report:

Private Sub btnPrintList_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnPrintList.Click
'Set up and fill the DataSet
Me.DsCalendar1.calMonthlyItems.Clear()
Me.daMonthlyItems.SelectCommand.Parameters("@tStartDate").Value = Me.Calendar1.VisibleDate
Me.daMonthlyItems.SelectCommand.Parameters("@tEndDate").Value = Me.Calendar1.VisibleDate.AddMonths(1).AddDays(-1)
Me.daMonthlyItems.Fill(Me.DsCalendar1)
'Populate and create the report
Dim crReport As New EventList
crReport.SetDataSource(DsCalendar1)
'Convert the report to a PDF stream
Dim strStream As New System.IO.BinaryReader(crReport.ExportToStream(CrystalDecisions.[Shared].Exp
ortFormatType.PortableDocFormat))
'Display the PDF content in the browser. Here's where I'd like the system to launch a new browser.
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.BinaryWrite(strStream.ReadBytes(strStream.BaseStream.Length))
Response.Flush()
Response.Close()
End Sub

Thanks!
 
D

DJ Dev

You can use Javascript for that.
Here...
if(IsPostBack)
{
start = StartDate.Value;
end = EndDate.Value;
if (strAdmin == "1")
{
surl = "AirTrans.aspx?start="+start+"&end="+end+"&section="+section+"&soc="+lblCompany;

}
else
{
surl = "AirTrans.aspx?start="+start+"&end="+end+"&section="+section;
}
features = "width=700, height=600, location=no, menubar=no,
status=no, toolbar=no, scrollbars=yes, resizable=yes";


script = "<script language = javascript> window.open(' " + surl +
" ','',' " + features + " ');</script>";
Response.Write(script);
lblStatus.Text = "Your Search is being carried out. The results
will open in a new browser window. You can search again using the
following form.";


}
HTH!
 
Joined
Jul 17, 2007
Messages
1
Reaction score
0
Hi im also having the same issue
i want to open this crystal file in pdf format in new window

Dim diskopts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim rptDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
'Dim strReportName As String = "prj_Report"
Dim strReportName As String = "Trans"
Dim strReportPath As String
If File.Exists(Server.MapPath("~/Report/" & strReportName & ".rpt")) Then
strReportPath = Server.MapPath("~/Report/" & strReportName & ".rpt")
Else
'Label1.Text = "File Not Found"
End If
Dim fnc As New Functionclass
Dim empstr As String = "Select * from tbl_emp where empno=" & Txtempno.Text
Dim rdemp As New Data.DataTable
fnc.fillTable(rdemp, empstr)
If rdemp.Rows.Count = 0 Then Exit Sub
Dim str As String = "SELECT * FROM [TimeSheet].[syed].[Trn_TblActivity] where Empno=" & Txtempno.Text & " and Date between'" & GMDatePicker1.Date.ToShortDateString & "' and '" & GMDatePicker2.Date.ToShortDateString & "' "
Dim ds As New Data.DataSet
Dim da As New SqlDataAdapter(str, sqlconn)
Dim cmd As New SqlCommand
If sqlconn.State = Data.ConnectionState.Closed Then sqlconn.Open()
Try
If sqlconn.State = Data.ConnectionState.Open Then
da.Fill(ds, "Trn_TblActivity")
rptDocument.Load(strReportPath)
rptDocument.SetDataSource(ds)
rptDocument.SetParameterValue("From", GMDatePicker1.Date.ToShortDateString)
rptDocument.SetParameterValue("To", GMDatePicker2.Date.ToShortDateString)
rptDocument.SetParameterValue("fname", fnc.FixNull(rdemp.Rows(0).Item("Fname")) & " " & fnc.FixNull(rdemp.Rows(0).Item("Mname")) & " " & fnc.FixNull(rdemp.Rows(0).Item("Lname")))
'rptDocument.SetParameterValue("mname", rdemp.Rows(0).Item("Mname"))
'rptDocument.SetParameterValue("lname", rdemp.Rows(0).Item("Lname"))
rptDocument.SetParameterValue("SectionCde", rdemp.Rows(0).Item("sectioncde"))
rptDocument.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
rptDocument.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
diskopts.DiskFileName = Server.MapPath("~/Report/" & strReportName & ".pdf")
rptDocument.ExportOptions.DestinationOptions = diskopts
rptDocument.Export()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-disposition", "inline; target=" & "_blank")
Response.Redirect("~/Report/" & strReportName & ".pdf")
Response.Flush()
'CrystalReportViewer1.ReportSource = rptDocument
'CrystalReportViewer1.DataBind()
'CrystalReportViewer1.DisplayToolbar = False
End If
Catch ex As Exception
'Return False
Finally
sqlconn.Close()
End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top