Solved

CrystalReport not taking parameters on button click

Posted on 2011-09-29
4
998 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

631 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