Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CrystalReport not taking parameters on button click

Posted on 2011-09-29
4
Medium Priority
?
1,004 Views
Last Modified: 2012-06-22
dear experts,

i have a crystal report in asp.net, c# which gets data from a mssql stored procedure
this stored procedure takes 2 params which i'm providing programmatically through c#

problem is, that this is working fine on page load
but when i change params and then click the submit button, and pass the params the same way in button click event, the params are going as null! (this i checked through the sql profiler that the procedure is getting null values)

what's going wrong?

{code attached}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

public partial class Super_SabkaSummary : System.Web.UI.Page
{
    UniClass uc = new UniClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["NjgPZBYCAgMPZBYIAgUPDxYCHgRUZXh0BQE1ZGQ"];

        if (cookie != null && cookie["role"].ToString() == "AD" && cookie["deptid"].ToString() == "999")
        {
            try
            {
                if (!(Page.IsPostBack))
                {
                    string from = uc.execscalar("select convert(varchar,min(changedate),103) from callhistoryarchive where changeevent='CALL OPEN'");
                    onlinesince.Text = "System online since " + from;
                    txtdatefrom.Text = from;
                    string today = DateTime.Today.ToString("dd/MM/yyyy");
                    txtdateto.Text = today;

                    ReportDocument rpt = new ReportDocument();

                    ParameterFields paramFields = new ParameterFields();
                    ParameterField paramField1 = new ParameterField();
                    ParameterField paramField2 = new ParameterField();
                    ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
                    ParameterDiscreteValue paramDiscreteValue2 = new ParameterDiscreteValue();

                    paramField1.Name = "@from";
                    paramDiscreteValue1.Value = txtdatefrom.Text;
                    paramField1.CurrentValues.Add(paramDiscreteValue1);

                    paramField2.Name = "@to";
                    paramDiscreteValue2.Value = txtdateto.Text;
                    paramField2.CurrentValues.Add(paramDiscreteValue2);

                    paramFields.Add(paramField1);
                    paramFields.Add(paramField2);

                    CrystalReportViewer2.ParameterFieldInfo = paramFields;

                    rpt.Load(Server.MapPath("~\\Reports\\CopSabkaSummary.rpt"));

                    CrystalReportViewer2.ReportSource = rpt;
                    CrystalReportViewer2.ToolbarImagesFolderUrl = "~\\images\\toolbar\\";
                    CrystalReportViewer2.LogOnInfo = uc.letsdosomething();
                }

                CrystalReportViewer2.Visible = true;
            }
            catch (Exception ex)
            { }
        }
        else
            Response.Redirect(@"~/Default.aspx");
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ReportDocument rpt = new ReportDocument();

        ParameterFields paramFields = new ParameterFields();
        ParameterField paramField1 = new ParameterField();
        ParameterField paramField2 = new ParameterField();
        ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
        ParameterDiscreteValue paramDiscreteValue2 = new ParameterDiscreteValue();

        paramField1.Name = "@from";
        paramDiscreteValue1.Value = txtdatefrom.Text;
        paramField1.CurrentValues.Add(paramDiscreteValue1);

        paramField2.Name = "@to";
        paramDiscreteValue2.Value = txtdateto.Text;
        paramField2.CurrentValues.Add(paramDiscreteValue2);


        paramFields.Add(paramField1);
        paramFields.Add(paramField2);

        CrystalReportViewer2.ParameterFieldInfo = paramFields;

        rpt.Load(Server.MapPath("~\\Reports\\CopSabkaSummary.rpt"));

        CrystalReportViewer2.ReportSource = rpt;
        CrystalReportViewer2.ToolbarImagesFolderUrl = "~\\images\\toolbar\\";
        CrystalReportViewer2.RefreshReport();
        CrystalReportViewer2.LogOnInfo = uc.letsdosomething();
    }
}

Open in new window

0
Comment
Question by:the_7th_king
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36814184
Did you debug and checked the value of txtdatefrom.Text and txtdateto.Text in the button click event? Whether it has correct values?
0
 
LVL 2

Author Comment

by:the_7th_king
ID: 36814187
yes! it has correct values!
0
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 2000 total points
ID: 36814197
Remove the CrystalReportViewer2.RefreshReport(); and see.
0
 
LVL 2

Author Closing Comment

by:the_7th_king
ID: 36814270
thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question