Search code examples
c#asp.netcrystal-reports

Crystal report viewer asking parameters again when clicking on the tool bar (sub Report anything) and in return showing same main page


It is an old application it showing crystal report on the Web page but the problem is that when I am clicking on anything it is asking for parameters again but showing the same report I have no idea how to do this because if I am clicking on sub Report same asking for parameters and showing the same report

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {

        var p = Request.QueryString["P"].ToString();
        var appId = int.Parse(Request.QueryString["appId"].ToString());
        var HE = new HIVAIDSEntities();
        var app = HE.ApplicatioNames.FirstOrDefault(x => x.Hivrp_app_name_pk == appId);



        //SQLReport report = new SQLReport();
        var report = new ReportDocument();
        //   Application.StartupPath 
        report.Load(filename: Server.MapPath(p));
        //Get SQL Server Details
        string zServer = app.Hivrp_server_name;
        string zDatabase = app.Hivrp_database_name;
        string zUsername = app.Hivrp_user_id;
        string zPassword = app.Hivrp_password;

        var ciReportConnection = new ConnectionInfo
        {
            ServerName = zServer,
            DatabaseName = zDatabase,
            UserID = zUsername,
            Password = zPassword
        };

        //TableLogOnInfo crTableLogoninfo = new TableLogOnInfo();
        //Assign data source details to tables

        foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
        {

            table.LogOnInfo.ConnectionInfo = ciReportConnection;
            table.ApplyLogOnInfo(table.LogOnInfo);

        }


        //Assign data source details to the report viewer
        if (this.CrystalReportViewer1.LogOnInfo != null)
        {
            TableLogOnInfos tlInfo = this.CrystalReportViewer1.LogOnInfo;
            foreach (TableLogOnInfo tbloginfo in tlInfo)
            {
                tbloginfo.ConnectionInfo = ciReportConnection;
            }
        }
        CrystalReportViewer1.ReportSource = report;
        CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
        CrystalReportViewer1.DisplayPage = true;

        CrystalReportViewer1.RefreshReport();
        Session["ReportDocument"] = report;
    }
    else
    {
        ReportDocument doc = (ReportDocument)Session["ReportDocument"];
        CrystalReportViewer1.ReportSource = doc;
        CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
        CrystalReportViewer1.DisplayPage = true;

        CrystalReportViewer1.RefreshReport();

    }

Solution

  • I just changed Page_Load function to Page_Init and everything is working fine :)