button_click event code of Customer_TotalSales.aspx are below...
protected void Button1_Click1(object sender, EventArgs e)
{
Session["@FromCustomerName"] = DropDownList1.SelectedValue;
Session["@ToCustomerName"] = DropDownList2.SelectedValue;
Session["@FromDate"] = DatePicker1.SelectedDate;
Session["@ToDate"] = DatePicker2.SelectedDate;
Response.Redirect("SessionVariable.aspx");
}
Another aspx SessionVariable.aspx its have 4 lable control which hold the session variable value and pass these value to crystal report Viewer control...
public partial class SessionVariable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LabFromCustomer.Text = Session["@FromCustomerName"].ToString();
LabToCustomer.Text = Session["@ToCustomerName"].ToString();
LabFromDate.Text = Session["@FromDate"].ToString();
LabToDate.Text = Session["@ToDate"].ToString();
CrystalReportViewer1.Visible = false;
CrystalReportViewer1.Visible = true;
CrystalReportSource1.Report.FileName = Server.MapPath("Reports/Customer_totalsalesTest.rpt");
ParameterDiscreteValue objDiscreteValue;
ParameterField objParameterField;
//Set value for first parameter.....
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabFromDate.Text;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@FromDate"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@ToDate"];
//Set value for second parameter......
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabToDate.Text;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
//Set value for Third parameter......
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabFromCustomer.Text;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@FromCustomerName"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objDiscreteValue = new ParameterDiscreteValue();
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@ToCustomerName"];
objDiscreteValue.Value = LabToCustomer.Text;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
CrystalReportViewer1.ReportSourceID = "CrystalReportSource1";
}
}
when i Execute First page then asking for 4 value DropdownList1,DropdownList2,Datepicker1,Datepicker2 ..i choose these value when i click button then SessionVariable.aspx execute and show the crystal report everything working nice till now ...
when i want change the value of parameter then i need to close the page and Re-Execute the page ........
please help me ...how can i Changed the parameter value to change theese value DropdownList1,DropdownList2,Datepicker1,Datepicker2 in one time execution.....whats i edit in my code for that.......
12 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bryian TanPosted Feb 6, 2010, 2:36 AM
Are you trying to open the page on a new window? if that the case, try something like:
add this markup on top of
and
protected void Button1_Click1(object sender, EventArgs e)
{
Random rnd = new Random();
Session["@FromCustomerName"] = null;
Session["@ToCustomerName"] = null;
Session["@FromDate"] = null;
Session["@ToDate"] = null;
Session["@FromCustomerName"] = DropDownList1.SelectedValue;
Session["@ToCustomerName"] = DropDownList2.SelectedValue;
Session["@FromDate"] = DatePicker1.SelectedDate;
Session["@ToDate"] = DatePicker2.SelectedDate;
// Response.Redirect("SessionVariable.aspx?r=" + rnd.Next(1000, 999999).ToString());
string strURL = "SessionVariable.aspx?r=" + rnd.Next(1000, 999999).ToString();
Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", "OpenPage('" + strURL + "');", true);
}
The Button1.Attributes.Add.. will execute the client side code first which is the window.open, but the Session value on the server side is not available yet, and it will cause null exception error on SessionVariable.aspx page. So, what we doing now is set the session variable first, and then open a new window through the JavaScript.
Hope that help.
Thanks,
Bryian Tan
vaquas khanPosted Feb 6, 2010, 5:49 AM
vaquas khanPosted Feb 6, 2010, 1:46 AM
Bryian TanPosted Feb 4, 2010, 10:30 AM
I think that caused by the browser cache. To bypass that, include a QueryString with different value for each request. For instance,
protected void Button1_Click1(object sender, EventArgs e)
{
Random rnd = new Random();
Session["@FromCustomerName"] = null;
Session["@ToCustomerName"] = null;
Session["@FromDate"] = null;
Session["@ToDate"] = null;
Session["@FromCustomerName"] = DropDownList1.SelectedValue;
Session["@ToCustomerName"] = DropDownList2.SelectedValue;
Session["@FromDate"] = DatePicker1.SelectedDate;
Session["@ToDate"] = DatePicker2.SelectedDate;
Response.Redirect("SessionVariable.aspx?r=" + rnd.Next(1000, 999999).ToString());
}
Thanks,
Bryian Tan
vaquas khanPosted Feb 4, 2010, 2:04 AM
vaquas khanPosted Feb 4, 2010, 1:40 AM
Bryian TanPosted Feb 3, 2010, 1:56 PM
That kind of odd, because the session should get over written by the new selected value the second time you click on the button. Anyway, try setting the session to null before assigning them any value and see how it goes.
Thanks, Bryian Tan
vaquas khanPosted Feb 3, 2010, 8:35 AM
i have two page first.aspx which have four control DropdownList1,DropdownList2,Datepicker1,Datepicker2 ..and Button
and code behind file is like....
first.aspx.cs..
protected void Button1_Click1(object sender, EventArgs e)
{
Session["@FromCustomerName"] = DropDownList1.SelectedValue;
Session["@ToCustomerName"] = DropDownList2.SelectedValue;
Session["@FromDate"] = DatePicker1.SelectedDate;
Session["@ToDate"] = DatePicker2.SelectedDate;
Button1.Attributes.Add("onclick", "window.open('Second.aspx','','height=1000,width=1000');return false");
In Second.Aspx i have 4 lable control (hidden)which hold the value of session variable and pass crystal report desecrate value...
Second.aspx.cs....
protected void Page_Load(object sender, EventArgs e)
{
CrystalReportViewer1.Visible = false;
LabFromCustomer.Text = Session["@FromCustomerName"].ToString();
LabToCustomer.Text = Session["@ToCustomerName"].ToString();
LabFromDate.Text = Session["@FromDate"].ToString();
LabToDate.Text = Session["@ToDate"].ToString();
CrystalReportViewer1.Visible = true;
CrystalReportSource1.Report.FileName = Server.MapPath("Reports/Customer_totalsalesTest.rpt");
ParameterDiscreteValue objDiscreteValue;
ParameterField objParameterField;
//Set value for first parameter.....
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabFromDate.Text;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@FromDate"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@ToDate"];
//Set value for second parameter......
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabToDate.Text;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
//Set value for Third parameter......
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabFromCustomer.Text;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@FromCustomerName"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objDiscreteValue = new ParameterDiscreteValue();
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@ToCustomerName"];
objDiscreteValue.Value = LabToCustomer.Text;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
CrystalReportViewer1.ReportSourceID = "CrystalReportSource1";
// CrystalReportViewer1.RefreshReport();
}
when i Run First.aspx and pass the value to these control DropdownList1,DropdownList2,Datepicker1,Datepicker2 .. and click the Button1 the pop up windows show the report according to my parameter...everything nice working till now ....but when i closed the pop up windows of report and again choose the another value of parameter and then click button1 but its give the previous value how can i solve this problem...............please help me....
Gaurish KumarPosted Feb 3, 2010, 6:58 AM
try this or use back button in your second page.
protected void Button1_Click1(object sender, EventArgs e)
{
Session["@FromCustomerName"] = DropDownList1.SelectedValue;
Session["@ToCustomerName"] = DropDownList2.SelectedValue;
Session["@FromDate"] = DatePicker1.SelectedDate;
Session["@ToDate"] = DatePicker2.SelectedDate;
LabFromCustomer.Text = Session["@FromCustomerName"].ToString();
LabToCustomer.Text = Session["@ToCustomerName"].ToString();
LabFromDate.Text = Session["@FromDate"].ToString();
LabToDate.Text = Session["@ToDate"].ToString();
CrystalReportViewer1.Visible = false;
CrystalReportViewer1.Visible = true;
CrystalReportSource1.Report.FileName = Server.MapPath("Reports/Customer_totalsalesTest.rpt");
ParameterDiscreteValue objDiscreteValue;
ParameterField objParameterField;
//Set value for first parameter.....
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabFromDate.Text;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@FromDate"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@ToDate"];
//Set value for second parameter......
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabToDate.Text;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
//Set value for Third parameter......
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = LabFromCustomer.Text;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@FromCustomerName"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objDiscreteValue = new ParameterDiscreteValue();
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@ToCustomerName"];
objDiscreteValue.Value = LabToCustomer.Text;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
CrystalReportViewer1.ReportSourceID = "CrystalReportSource1";
}
Rekha SinghPosted Feb 3, 2010, 6:43 AM
******************************************
Mark Accepted if u find it helpful
vaquas khanPosted Feb 3, 2010, 5:04 AM
Gaurish KumarPosted Feb 3, 2010, 4:21 AM
why are you redirecting to another page. do code in first page like this:
so whenever you will change the value of dropdown and datepicker control , it also changes the parameter value for crystal reports.