Solved

CrystalReport not taking parameters on button click

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

803 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