Solved

CrystalReport not taking parameters on button click

Posted on 2011-09-29
4
994 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET(C#) Eliminating weekends from a date range 2 46
Count If in Crystal Reports 2 19
SSRS Deployment problem 5 67
C# Service FileSystemwatcher isse 9 27
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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