Hi guys.
I have a problem with a view state.
The problem is when I am trying to get value it is giving me the default one but show me correct value from view state.
Please Help.
Here is the code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxEditors;
using BlueInkt.XPO.Reports;
using BlueInkt.Common.Utils;
using System.Collections.ObjectModel;
using BlueInkt.Common.Utils.XML;
using System.Diagnostics;
namespace BlueInkt.Controls.ReportControls
{
public class DateSelector : CustomControl, IFilterControl
{
private static string Resource_Everyting = Resources.GetResource("backoffice/all", "Everything");
private static string Resource_Free = Resources.GetResource("backoffice/all", "Free");
private static string Resource_Today = Resources.GetResource("backoffice/all", "Today");
private static string Resource_Yesterday = Resources.GetResource("backoffice/all", "Yesterday");
private static string Resource_Last7days = Resources.GetResource("backoffice/all", "Last7days");
private static string Resource_Last30days = Resources.GetResource("backoffice/all", "Last30days");
private static string Resource_ThisMonth = Resources.GetResource("backoffice/all", "ThisMonth");
private static string Resource_LastMonth = Resources.GetResource("backoffice/all", "LastMonth");
private static string Resource_Last3months = Resources.GetResource("backoffice/all", "Last3months");
private static string Resource_ThisYear = Resources.GetResource("backoffice/all", "ThisYear");
private static string Resource_LastYear = Resources.GetResource("backoffice/all", "LastYear");
private static string Resource_Apply = Resources.GetResource("lead/dashboard", "Apply");
private static string Resource_From = Resources.GetResource("lead/dashboard", "From");
private static string Resource_To = Resources.GetResource("lead/dashboard", "To");
private static string ResourceSet = "lead/dashboard/filters";
private int createdCount = 0;
private List<string> DS_columns = new List<string>();
public ReadOnlyCollection<string> Columns
{
get { return DS_columns.AsReadOnly(); }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
this.CreateChildControls();
base.OnLoad(e);
}
public int CreatedControlsCount
{
get
{
return this.createdCount;
}
}
public void CreateOne(string ColumnName)
{
this.DS_columns.Add(ColumnName);
}
private void AddOne(string ColumnName)
{
HtmlTable tblCustomControl = new HtmlTable();
HtmlTableRow tr1 = new HtmlTableRow();
HtmlTableRow tr2 = new HtmlTableRow();
HtmlTableRow tr3 = new HtmlTableRow();
HtmlTableRow tr4 = new HtmlTableRow();
HtmlTableCell td11 = new HtmlTableCell();
HtmlTableCell td12 = new HtmlTableCell();
HtmlTableCell td21 = new HtmlTableCell();
HtmlTableCell td22 = new HtmlTableCell();
HtmlTableCell td31 = new HtmlTableCell();
HtmlTableCell td32 = new HtmlTableCell();
HtmlTableCell td41 = new HtmlTableCell();
HtmlTableCell td42 = new HtmlTableCell();
ASPxLabel PeriodLable = new ASPxLabel { ID = "lblPeriod_" + ColumnName, Text = Resources.GetResource(ResourceSet, "DateSelecter_" + ColumnName) };
ASPxLabel FromLable = new ASPxLabel { ID = "lblFrom_" + ColumnName, Text = Resource_From };
ASPxLabel ToLable = new ASPxLabel { ID = "lblTo_" + ColumnName, Text = Resource_To };
ASPxComboBox PeriodComboBox = new ASPxComboBox { ID = "cmbPeriod_" + ColumnName };
ListEditItem EverytingLEI = new ListEditItem(Resource_Everyting, "Everyting");
ListEditItem FreeLEI = new ListEditItem(Resource_Free, "Free");
ListEditItem TodayLEI = new ListEditItem(Resource_Today, "Today");
ListEditItem YesterdayLEI = new ListEditItem(Resource_Yesterday, "Yesterday");
ListEditItem Last7daysLEI = new ListEditItem(Resource_Last7days, "Last7days");
ListEditItem Last30daysLEI = new ListEditItem(Resource_Last30days, "Last30days");
ListEditItem ThisMonthLEI = new ListEditItem(Resource_ThisMonth, "ThisMonth");
ListEditItem LastMonthLEI = new ListEditItem(Resource_LastMonth, "LastMonth");
ListEditItem Last3monthsLEI = new ListEditItem(Resource_Last3months, "Last3months");
ListEditItem ThisYearLEI = new ListEditItem(Resource_ThisYear, "ThisYear");
ListEditItem LastYearLEI = new ListEditItem(Resource_LastYear, "LastYear");
PeriodComboBox.Items.Add(EverytingLEI);
PeriodComboBox.Items.Add(FreeLEI);
PeriodComboBox.Items.Add(TodayLEI);
PeriodComboBox.Items.Add(YesterdayLEI);
PeriodComboBox.Items.Add(Last7daysLEI);
PeriodComboBox.Items.Add(Last30daysLEI);
PeriodComboBox.Items.Add(ThisMonthLEI);
PeriodComboBox.Items.Add(LastMonthLEI);
PeriodComboBox.Items.Add(Last3monthsLEI);
PeriodComboBox.Items.Add(ThisYearLEI);
PeriodComboBox.Items.Add(LastYearLEI);
td11.Controls.Add(PeriodLable);
td12.Controls.Add(PeriodComboBox);
ASPxDateEdit de = new ASPxDateEdit { ID = String.Format("de_{0}_DateFrom", ColumnName), ClientInstanceName = "DateFrom_" + ColumnName };
ASPxDateEdit deTo = new ASPxDateEdit { ID = String.Format("de_{0}_DateTo", ColumnName), ClientInstanceName = "DateTo_" + ColumnName };
PeriodComboBox.ClientSideEvents.SelectedIndexChanged = String.Format("function(s,e){{SetDates(s,e,{0}, {1});}}", de.ClientInstanceName, deTo.ClientInstanceName);
ASPxLabel ApplyLabel = new ASPxLabel { ID = string.Format("lblApply_{0}", ColumnName), ClientInstanceName = ID, Text = Resource_Apply };
ASPxCheckBox ApplyCheckBox = new ASPxCheckBox { ID = "chbApply_" + ColumnName, ClientInstanceName = ID };
Debug.WriteLine(string.Format("DateSelector.ApplyCheckBox.Checked = {0}", ApplyCheckBox.Checked));
td21.Controls.Add(FromLable);
td22.Controls.Add(de);
td31.Controls.Add(ToLable);
td32.Controls.Add(deTo);
td41.Controls.Add(ApplyLabel);
td42.Controls.Add(ApplyCheckBox);
tr1.Cells.Add(td11);
tr1.Cells.Add(td12);
tr2.Cells.Add(td21);
tr2.Cells.Add(td22);
tr3.Cells.Add(td31);
tr3.Cells.Add(td32);
tr4.Controls.Add(td41);
tr4.Controls.Add(td42);
tblCustomControl.Rows.Add(tr1);
tblCustomControl.Rows.Add(tr2);
tblCustomControl.Rows.Add(tr3);
tblCustomControl.Rows.Add(tr4);
Controls.Add(tblCustomControl);
EverytingLEI.Selected = true;
de.Date = new DateTime(2000, 1, 1);
deTo.Date = DateTime.Now;
this.createdCount++;
}
protected override void CreateChildControls()
{
foreach (string column in this.DS_columns)
{
this.AddOne(column);
}
}
public DateTime GetFromVaule(string ColumnName)
{
if (this.FindControl(String.Format("de_{0}_DateFrom", ColumnName)) != null)
{
string str = String.Format("de_{0}_DateFrom", ColumnName);
return ((ASPxDateEdit)this.FindControl(str)).Date;
}
else return DateTime.MinValue;
}
public DateTime GetToVaule(string ColumnName)
{
if (this.FindControl(String.Format("de_{0}_DateTo", ColumnName)) != null)
{
string str = String.Format("de_{0}_DateTo", ColumnName);
return ((ASPxDateEdit)this.FindControl(str)).Date;
}
else return DateTime.MaxValue;
}
public DateSelectorType GetKindValue(string ColumnName)
{
string CtrlID = "cmbPeriod_" + ColumnName;
if (this.FindControl(CtrlID) != null)
{
ASPxComboBox CBox = (ASPxComboBox)this.FindControl(CtrlID);
if (CBox.SelectedItem == null)
{
return DateSelectorType.Everything;
}
else
{
return DateSelectorHelper.JavasriptValueToDateSelectorType(CBox.SelectedItem.Value.ToString());
}
}
else return DateSelectorType.Everything;
}
public void SetAllValues(ReportCustom.DateInterval DInterval)
{
string CmbCtrlID = "cmbPeriod_" + DInterval.ColumnName;
string DEFromCtrlID = string.Format("de_{0}_DateFrom", DInterval.ColumnName);
string DEToCtrlID = string.Format("de_{0}_DateTo", DInterval.ColumnName);
string ApplyChkCtrlID = string.Format("chbApply_{0}", DInterval.ColumnName);
bool IsFree = (DInterval.Kind == DateSelectorType.Free);
if (this.FindControl(DEFromCtrlID) != null)
{
ASPxDateEdit DateFromDE = (ASPxDateEdit)this.FindControl(DEFromCtrlID);
DateFromDE.Date = DInterval.DateFrom;
DateFromDE.ClientEnabled = IsFree;
}
if (this.FindControl(DEToCtrlID) != null)
{
ASPxDateEdit DateToDE = (ASPxDateEdit)this.FindControl(DEToCtrlID);
DateToDE.Date = DInterval.DateTo;
DateToDE.ClientEnabled = IsFree;
}
if (this.FindControl(CmbCtrlID) != null)
{
ASPxComboBox CBox = (ASPxComboBox)this.FindControl(CmbCtrlID);
CBox.Value = DateSelectorHelper.DateSelectorTypeToJavascriptValue(DInterval.Kind);
}
if(this.FindControl(ApplyChkCtrlID) !=null)
{
ASPxCheckBox ApplyChkBox = (ASPxCheckBox)this.FindControl(ApplyChkCtrlID);
ApplyChkBox.Checked = true;
}
}
public bool IsApplied(string ColumnName)
{
string ID = "chbApply_" + ColumnName;
if (this.FindControl(ID) != null)
{
return ((ASPxCheckBox)this.FindControl(ID)).Checked;
}
else
{
return false;
}
}
}
}
Please Help.