Got more questions? Find advice on: SQL | XML | Regular Expressions | Windows
in Search
Welcome to AspAdvice Sign in | Join | Help

Crystal .NET Blog

Sample codes, tips, random rantings on Crystal Reports, Crystal Enterprise etc...

Report Object not showing data in CR.Net web application on 2nd page

We got this question at Tech Ed San Diego, so I'm posting the solution up:

Problem


A web application built using Crystal Reports for Visual Studio .NET 2002/2003.  The Report Viewer Control is used to display a crystal report.   A report using this DHTML Viewer displays data correctly on the first page, however the second page of the report displays the Report Viewer Control instead of data.

Solution

Set the Report Source in the Page_Init Event, not the Page_Load Event.

The Report Viewer Control displays on the page instead of the data if the Report Source is not set in the Page_Init Event of the Web Form Viewer. When a Postback Event is executed back to the server, the Report Source must be set.

The following sample code demonstrates how to set the Report Source correctly in the Page_Init Event:

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

'CODEGEN: the Web Form Designer requires this method call

'Do not modify it using the code editor.

InitializeComponent()

crReportDocument = New ReportDocument

crReportDocument.Load("C:\Program Files\Microsoft Visual Studio .NET 2003\Crystal Reports\Samples\Reports\Feature Examples\Chart.rpt")

CrystalReportViewer1.ReportSource() = crReportDocument

====================
NOTE:

Postback occurs when the web server reprocesses the current viewer page because you sent new criteria. This occurs when you execute a click event from the Crystal web viewer's toolbar.
====================

Published Thursday, June 03, 2004 5:40 PM by crystal

Comments

 

crystal said:

Does this work with the push method of loading a crystal report? I am trying it and it does not seem to work. Do you have any suggestions?
August 6, 2004 9:26 AM
 

crystal said:

Yep, whether you push data in or not is not tied to the viewer issue. You can pass the database after the ceReportDocument.Load call.

Did you do that already?
August 9, 2004 9:53 AM
 

crystal said:

Thank you! Worked like a charm!
June 9, 2005 7:54 AM
Anonymous comments are disabled