1535180 - Parameter requested again when next page button is clicked

SAP Knowledge Base Article - Public

1535180 - Parameter requested again when next page button is clicked

Symptom

  1. Create a Web application to display Crystal report using Visual Studios 2008 .
  2. The report has a parameter and multiple pages.
  3. When next button in the viewer tool is pressed the parameter needs to be passed again.

Environment

  • Visual Studios 2008.
  • Crystal Reports 2008.
  • Web application is created in C#.

Reproducing the Issue

The following code(C#) is used in the application:

public partial class DailySummaryDisplay : System.Web.UI.Page
{
   ReportDocument dailyReportSummary = new ReportDocument();

   protected void Page_Load(object sender, EventArgs e)
   {
      if (!IsPostBack)
       {
           CrystalReportViewer1.Visible = false;
       }
     else
     if (CrystalReportViewer1.Visible == true)
       {
            BindReport();
       }
   }

   protected void btnPreview_Click(object sender, EventArgs e)
   {
        BindReport();
        CrystalReportViewer1.Visible = true;
    }

   private void BindReport()
   {
        dailyReportSummary.Load(Server.MapPath("~/Reports/DailySummary.rpt"));
       
        dailyReportSummary.SetDataSource((DataTable)ta.GetAllTransactions());

        CrystalReportViewer1.DisplayGroupTree = false;
        CrystalReportViewer1.HasCrystalLogo = false;
        CrystalReportViewer1.HasPrintButton = false;
        CrystalReportViewer1.HasExportButton = false;
        CrystalReportViewer1.HasToggleGroupTreeButton = false;
        CrystalReportViewer1.ReportSource = dailyReportSummary;
   }

   public void Page_Unload(object sender, EventArgs e)
   {
        //Clean up resources. Force garbage collection.
       dailyReportSummary.Close();
       dailyReportSummary.Dispose();
       GC.Collect();
   }

  
  System.IO.Stream stream = reportDocument.ExportToStream (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

Cause

  • Viewer is not being made visible in postback.
  • Parameters are not passed through code.

Resolution

Changes made in the following Section:

A) Page_Load event:

ReportDocument dailyReportSummary = new ReportDocument();

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CrystalReportViewer1.Visible = false;
            }
            else
            //Code removed.   
            //if (CrystalReportViewer1.Visible == true)
            {
                 CrystalReportViewer1.Visible = true;
                 BindReport();
             }

        }

B) Parameter is passed in the BindReport() method:

private void BindReport()        
        {  
             dailyReportSummary.Load(Server.MapPath("Product Catalog.rpt"));
             dailyReportSummary.FileName = Server.MapPath("Product Catalog.rpt");
             /// PASSING THE PARAMETER VALUE
             dailyReportSummary.SetParameterValue("My Parameter", "MyParameterValue");
             CrystalReportViewer1.DisplayGroupTree = false;
             CrystalReportViewer1.HasCrystalLogo = false;
             CrystalReportViewer1.HasPrintButton = false;
             CrystalReportViewer1.HasExportButton = false;
             CrystalReportViewer1.HasToggleGroupTreeButton = false;
             CrystalReportViewer1.ReportSource = dailyReportSummary;
         }

See Also

Forum Link:
http://forums.sdn.sap.com/thread.jspa?threadID=1842489&tstart=0

Keywords

dot net, vs, sdk, api , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports, version for Visual Studio .NET 2008