views:

77

answers:

1

I just upgraded to the beta 2 of Crystal Reports for Visual Studio 2010 and I'm not able to print, export, zoom, or change pages while using the web control in an ASP.NET MVC application.

I can get the report to run and display just fine on the webpage. All of the buttons have images, and the report data looks exactly as it should on the page.

In VS2010 while looking at the .rpt I can click 'Report Preview' and get the report to run and print, export, zoom, etc...this appears to use the windows control to render the report and not the web control. Thus I believe my report file itself is valid.

While on the webpage viewing the report in the Crystal Reports Viewer I get different functionality when I try each of the buttons:

  • Print : Click the print button once, the report goes back to the web server, re-runs the report, but then comes back to the webpage and does nothing. Press it again and it opens a new tab with the same report in this new tab.
  • Export : Export opens the dialog box asking me which format I would like to export to. Once I make a selection it performs the same functions print does, goes to the back end, then nothing. Pressing export again opens up a new tab with the report in it.
  • Zoom/Change Page - Both of these options pop-up with a dialog box, a spinner, and then freeze the page.

I get the same behavior regardless of which browser I use, (IE, Chrome, Mozilla), and all of the browsers have pop-up blocker turned off.

Using Chrome's developer tools I do get two errors on the page:

  • JobHistory:59[The HTML that caused this error was generated by a script.] Unmatched encountered. Ignoring tag.
  • JobHistory:59[The HTML that caused this error was generated by a script.] Unmatched encountered. Ignoring tag.

Other items I've tried:

  • Removed all previous versions of Crystal Reports
  • Uninstalled and then reinstalled beta 2 of Crystal Reports
  • Restarted my solution from scratch, originally it was an upgrade from 2008.
  • Cross posted this question on the Crystal Reports beta 2 forums

Any thoughts or suggestions on things I could try are greatly appreciated.

A: 

Crystal Report's Report Viewer control is a server side control, as such, it doesn't function properly when part of an MVC view page. Hence, when I tried to print or export, causing a post back, I would continually see a page refresh, instead of printing or exporting.

This behavior is different from ASP.NET MVC version 1 that I used with Visual Studio 2008 and the version of Crystal Reports that came with VS2008. In VS2010 and, as of now beta of, Crystal Reports 2010, the Report Viewer control needs to be on a plain old aspx page and not part of an MVC view page.

To accomplish this I took the following steps, many of these steps are the sames ones I used before in a related question, but I have tweaked them for the new behavior seen in VS2010 and CrystalReports 2010: StackOverflow.com: CrystalReportViewer Buttons Broken using MVC Framework

  • In my controller I invoke the proper calls to my model to obtain my report data,

List<JobSummaryBody> body = model.GetJobSummaryBody(jobId, startDate, endDate);

  • Next, I create a varible for the report itself, in this case:

JobSummaryByDate summary = new JobSummaryByDate();

Note: JobSummaryByDate is a data type created by Crystal Reports when I design my report, it is code generated. Think of it as all of the data that your designed report is going to need.

  • Next I set the the data source, the row data, for the report I just created

summary.SetDataSource(body);

  • Lastly I store my report data in Session, and do a Response.Redirect to my aspx page that holds the Crystal Reports Viewer

Session["ReportData"] = summary; Response.Redirect("~/CrystalReports/JobSummaryByDateView.aspx");

Note: I have created a new top level folder in my project called "CrystalReports", the folder can actually be navigated to by URL.

  • The source page for JobSummaryByDateView.asp is very striaght forward, add the Crystal Report Viewer, in this case I gave it an ID of Report Viewer:

    <CR:CrystalReportViewer ID="ReportViewer" runat="server" AutoDataBind="true" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" ToolPanelView="None" HasDrilldownTabs="False" HasDrillUpButton="False" HasSearchButton="False" HasToggleGroupTreeButton="False" HasToggleParameterPanelButton="False" ReuseParameterValuesOnRefresh="True" />

  • Lastly, on the code behind page I set the ReportViewer.ReportSource to my Report Data I generated in my controller:

protected void Page_Init(object sender, EventArgs e) { ReportViewer.ReportSource = Session["ReportData"]; }

ben