Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

19.12 Exporting to a New Browser Window

Exporting to a New Browser Window

I frequently see people on the forum asking how to export reports to a new browser window. This keeps the report output separate from your web application’s browser. The reason that this is important is because users have a tendency to close the browser window when finished reading a report. They don’t click the Back button to go to the previous page that launched the report. If you have the report in the same browser window as your application, this will close your application and the user has to start over again.

Printing a report in a new browser window is actually a function of .NET and not Crystal Reports. It requires knowing how to build the web page in such a way that the report links will open a new browser window. Nonetheless, we’ll look at how to modify your web application to use this functionality with your reports.

.NET has two methods of opening a report in a new browser window. Both methods are easy to use. The first method uses a Hyperlink control. Simply put the hyperlink control on your web form and set the following two properties:

  • NavigateUrl: The .aspx page that prints the report.
  • Target: Set to “_blank”

When the user clicks the link, it opens the web page hosting your report in a new window. The second method of opening the report in a new browser window uses javascript code. This is necessary when you want to open the report in response to an event of a web control. For example, you could open the report when the user clicks on a button. The JavaScript code calls the window.open() method to open the new browser window. Here is sample code associated with the Click event of a button. When you use this code in your application, change the name of the web page, “ShowReport.aspx” to the name of the page in your application which is hosting the report.

Listing 19-8. Use Javascript to open a report in a new browser window.
[VB.NET]
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Response.Write("")
End Sub
[C#]
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("");
}

It’s as simple as that! Remember to put the code that instantiates and exports your report in the Page_Init() method of the new web page.