Solved

CrystalReport not taking parameters on button click

Posted on 2011-09-29
4
987 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
Comment Utility
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
Comment Utility
yes! it has correct values!
0
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
Comment Utility
Remove the CrystalReportViewer2.RefreshReport(); and see.
0
 
LVL 2

Author Closing Comment

by:the_7th_king
Comment Utility
thanks!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now