'Crystal Report Viewer - ASP.net

I am attempting to add a Crystal Report Viewer to an asp.net web app. We are using reports that were created for our desktop application so they are already created and functional. We are connecting to the same database with the same query across both platforms and the database and query is set up in the report designer.

Here's a preview from one of the reports in Visual Studio Pro 2015 in the asp.net project: enter image description here

I have added the following line to my Reports.aspx page:

<CR:CrystalReportViewer ID="crptViewer" runat="server" AutoDataBind="true" />

I added a "Crystalreportviewers13" folder to the root of the application directory with the content of crystal report installation.

I have added the following to my web.config file:

<configuration>
  <configSections>
    <sectionGroup name="businessObjects">
      <sectionGroup name="crystalReports">
        <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null"/>
        <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler"/>
      </sectionGroup>
    </sectionGroup>
  </configSections>
   <businessObjects>
    <crystalReports>
      <rptBuildProvider>
        <add embedRptInResource="true"/>
     </rptBuildProvider>
    <crystalReportViewer>
              <add key="ResourceUri" value="/crystalreportviewers13" />
      </crystalReportViewer>
    </crystalReports>
  </businessObjects>

I have tried several strategies on the code behind based on different stack overflow suggestions. Here's what I've tried so far:

On Button Click:

public partial class Reports : System.Web.UI.Page

{

ReportDocument rptDocument;
protected void Page_Load(object sender, EventArgs e)
    {
        string stack = "Page_Load()(Reports.aspx.cs)";
        try
        {
            if (Session["report"] != null)
            {
                crptViewer.ReportSource = Session["report"];

            }
        }
        catch (Exception EX)
        {
            IOClass.appendLog("Error in " + stack, EX.Message);
        }
    }

   //Button Click
   protected void generateReport(object sender, EventArgs e)
    {

        rptDocument = new ReportDocument();
        rptDocument.Load(Server.MapPath("~/Crystal/UserListing.rpt"));

        rptDocument.SetParameterValue("Company", 1);

        Session["report"] = rptDocument;


    }
}

and On Load:

public partial class Reports : System.Web.UI.Page
{

    ReportDocument rptDocument;
    protected void Page_Load(object sender, EventArgs e)
    {
        string stack = "Page_Load()(Reports.aspx.cs)";
        try
        {
           rptDocument = new ReportDocument();
           rptDocument.Load(Server.MapPath("~\\Crystal\\UserListing.rpt"));
           crptViewer.ReportSource = rptDocument;

           //I have tried with and without the following:
           //crptViewer.DataBind();
           //and
           //crptViewer.RefreshReport();
        }
        catch (Exception EX)
        {
            IOClass.appendLog("Error in " + stack, EX.Message);
        }
    }
}

When the page loads in both cases this is what I get:

enter image description here

I'm doing exception logging on the load function and I do not get any exceptions.

Any ideas what I'm doing wrong here? Let me know if I can provide any other information.

Thank you for your time



Solution 1:[1]

Remove <asp:Content> on aspx and use the default html page like this...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="myproject.WebForm1" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script type="text/javascript" src="/crystalreportviewers13/js/crviewer/crv.js">
        </script> 
</head>
<body>
    <form id="form1" runat="server">
        <div>
		    <asp:Button ID="btnShowReport" runat="server" Text="Show Report" OnClick="btnShowReport_Click" />
            <CR:CrystalReportViewer ID="JobRepairReportViewer" runat="server" AutoDataBind="true" />
        </div>
    </form>
</body>
</html>

On Load in aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Diagnostics;
using CrystalDecisions.CrystalReports.Engine;

namespace iconequipment
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnShowReport_Click(object sender, EventArgs e)
        {
            ReportDocument rpt = new ReportDocument();
            rpt.Load(Server.MapPath("JobRepairReport.rpt"));
            //rpt.SetParameterValue("JobID", this.txtJobID.Text);
            this.JobRepairReportViewer.ReportSource = rpt;
            this.JobRepairReportViewer.RefreshReport();
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taenjai Kaewdee