T
TS
i have a composite control that has dropdowns on them. The page will post
back on change, but their events won't raise. Can anyone tell me whats going
on? I tried to use the IPostBackDataHandler to try to get a hold of the
control to set values and such, but it has been no help. I'm confused at how
this control is supposed to work. I want it to be self contained so that
when a control changes, it posts back and then reloads its dependent drop
down lists with data that is filtered based on the value of the control that
changed.
Every time the page posts back to server, the it hits the init and load
events and createchildcontrols, but thats it. i can't get into the
XXX_SelectedIndexChanged events for some reason even though they are wired
to do so.
Any help will be appreaciated as i'm starting to feel dumb.
using System;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Operations.Teams.Business;
using Operations.Teams.Data;
using Operations.Teams.Reporting;
using Operations.Teams.Reporting.WebControls;
namespace Operations.Teams.Web.ReportControls
{
/// <summary>
/// Summary description for FiscalAgentHierarchy.
/// </summary>
public class FiscalAgentHierarchy : Control, IReportParameterControl,
IPostBackDataHandler
{
public FiscalAgentHierarchy()
{
Parameters.Add(new Parameter("@SchoolYear"));
Parameters.Add(new Parameter("@ReportingGroup"));
Parameters.Add(new Parameter("@FiscalAgentID"));
Parameters.Add(new Parameter("@FundingSourceID"));
Parameters.Add(new Parameter("@ProviderID"));
Parameters.Add(new Parameter("@SiteID"));
Parameters.Add(new Parameter("@ClassID"));
Parameters["@SchoolYear"].Value = 2006;
}
#region Events
public bool LoadPostData(string postDataKey, NameValueCollection postData)
{
string postedValue = postData[postDataKey];
return true;
}
public void RaisePostDataChangedEvent()
{
rysReportingYearSelector_ReportingYearChanged(this, EventArgs.Empty);
}
protected override void LoadViewState(object savedState)
{
string zasdf="asdlfkjds";
}
protected override object SaveViewState()
{
string zsad="asdf";
}
protected override void OnInit(EventArgs e)
{
//this.EnsureChildControls();
// Do whatever the control usually does OnInit
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
//this.EnsureChildControls();
// Do whatever the control usually does OnInit
base.OnLoad(e);
}
private void rysReportingYearSelector_ReportingYearChanged(object sender,
EventArgs e)
{
this.LoadFundingSource();
this.LoadProviders();
}
private void fasFiscalAgent_FiscalAgentChanged(object sender, EventArgs e)
{
this.LoadFundingSource();
this.LoadProviders();
}
private void ddlProviders_SelectedIndexChanged(object sender, EventArgs e)
{
LoadSites();
}
private void ddlSites_SelectedIndexChanged(object sender, EventArgs e)
{
LoadClasses();
}
#endregion
protected override void CreateChildControls()
{
rysReportingYearSelector = new ReportingYearReportSelector();
fasFiscalAgent = new FiscalAgentReportSelector();
this.ddlFundingSource = new DropDownList();
this.ddlProviders = new DropDownList();
this.ddlSites = new DropDownList();
this.ddlClasses = new DropDownList();
rysReportingYearSelector.ID = ReportingYearSelectorControlId;
fasFiscalAgent.ID = FiscalAgentSelectorControlId;
ddlFundingSource.ID = FundingSourceControlId;
ddlProviders.ID = ProvidersControlId;
ddlSites.ID = SitesControlId;
ddlClasses.ID = ClassesControlId;
// Assign these controls' Page property because when they try to access Page
they get null reference - apparently they aren't in the control tree at that
point
rysReportingYearSelector.Page = this.Page;
fasFiscalAgent.Page = this.Page;
rysReportingYearSelector.ReportingYearChanged += new
EventHandler(rysReportingYearSelector_ReportingYearChanged);
fasFiscalAgent.FiscalAgentChanged += new
EventHandler(fasFiscalAgent_FiscalAgentChanged);
ddlProviders.SelectedIndexChanged += new
EventHandler(ddlProviders_SelectedIndexChanged);
ddlSites.SelectedIndexChanged += new
EventHandler(ddlSites_SelectedIndexChanged);
fasFiscalAgent.IsSubmitOnChange = true;
ddlProviders.AutoPostBack = true;
ddlSites.AutoPostBack = true;
// this.SchoolYear = rysReportingYearSelector.SchoolYear;
// check if can populate funding sources and providers (because fiscalAgent
has been saved in session)
if(this.fasFiscalAgent.SelectedFiscalAgentName != string.Empty)
{
LoadFundingSource();
LoadProviders();
}
else
{
ddlFundingSource.Visible = false;
ddlProviders.Visible = false;
}
// Initially set to false until their direct parent's selection has been
made (all other controls will have data on page load)
ddlSites.Visible = false;
ddlClasses.Visible = false;
// start containing table
this.Controls.Add(WebHelper.MakeLiteral("<table cellpadding=0
cellspacing=0><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>"));
this.Controls.Add(rysReportingYearSelector);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>"));
this.Controls.Add(fasFiscalAgent);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Funding
Source</td><td>"));
this.Controls.Add(ddlFundingSource);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Providers</td><td>")
);
this.Controls.Add(ddlProviders);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Sites</td><td>"));
this.Controls.Add(ddlSites);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Classes</td><td>"));
this.Controls.Add(ddlClasses);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
// end containing table
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
}
private void LoadFundingSource()
{
int fiscalAgentId = this.fasFiscalAgent.SelectedFiscalAgentId;
if(fiscalAgentId != int.MinValue)
{
this.ddlFundingSource.Visible = true;
this.ddlFundingSource.DataSource = FiscalAgentFunding.Find(fiscalAgentId);
this.ddlFundingSource.DataTextField = "ShortDescription";
this.ddlFundingSource.DataValueField = "CodeId";
this.ddlFundingSource.DataBind();
if(this.ddlFundingSource.Items.Count > 1)
this.ddlFundingSource.Items.Insert(0, new ListItem(string.Empty,
string.Empty));
}
else
{
this.ddlFundingSource.Visible = false;
}
}
private void LoadProviders()
{
int fiscalAgentId = fasFiscalAgent.SelectedFiscalAgentId;
if(fiscalAgentId != int.MinValue)
{
ddlProviders.Visible = true;
ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
rysReportingYearSelector.ReportingYearStartDate,
rysReportingYearSelector.ReportingYearEndDate);
ddlProviders.DataTextField = "ProviderName";
ddlProviders.DataValueField = "ProviderId";
ddlProviders.DataBind();
ddlProviders.Items.Insert(0, new ListItem(string.Empty, string.Empty));
}
else
{
this.ddlProviders.Items.Clear();
this.ddlProviders.Visible = false;
}
LoadSites();
}
private void LoadSites()
{
if(ddlProviders.SelectedValue != string.Empty)
{
// Load the Site search parameters.
SiteFindArgs siteFindArgs=new SiteFindArgs();
siteFindArgs.FiscalAgentId=Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgen
tId);
ddlSites.Visible = true;
ddlSites.DataSource = Business.Site.Find(siteFindArgs);
ddlSites.DataTextField = "Name";
ddlSites.DataValueField = "SiteId";
ddlSites.DataBind();
ddlSites.Items.Insert(0, new ListItem(string.Empty, string.Empty));
}
else
{
ddlSites.Items.Clear();
ddlSites.Visible = false;
}
LoadClasses();
}
private void LoadClasses()
{
if(ddlSites.SelectedValue != string.Empty)
{
ClassFindArgs adultEdClassFindArgs = new ClassFindArgs();
adultEdClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
adultEdClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;
adultEdClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;
adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;
adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
ddlClasses.Visible = true;
ddlClasses.DataSource = Class.Find(classFindArgs);
ddlClasses.DataTextField = "Name";
ddlClasses.DataValueField = "ClassId";
ddlClasses.DataBind();
ddlClasses.Items.Insert(0, new ListItem(string.Empty, string.Empty));
}
else
{
ddlClasses.Items.Clear();
ddlClasses.Visible = false;
}
}
#region Public Properties
#region IReportParameterControl Members
public object ParameterValue
{
get{ return null; }
set{ /*do nothing */ }
}
public ParameterCollection Parameters
{
get{ return parameters; }
set{ parameters = value;}
}
#endregion
public int SchoolYear
{
get{ return (int) ViewState["SchoolYear"]; }
set{ ViewState["SchoolYear"] = value; }
}
#endregion
#region Private Member Variables
private ReportingYearReportSelector rysReportingYearSelector;
private FiscalAgentReportSelector fasFiscalAgent;
private DropDownList ddlFundingSource;
private DropDownList ddlProviders;
private DropDownList ddlSites;
private DropDownList ddlClasses;
private ParameterCollection parameters = new ParameterCollection();
#endregion
#region Private Constants
private const string ReportingYearSelectorControlId =
"rysReportingYearSelector";
private const string FiscalAgentSelectorControlId =
"fasFiscalAgentSelector";
private const string FundingSourceControlId = "ddlFundingSource";
private const string FundingSourceLabelControlId = "lblFundingSource";
private const string ProvidersControlId = "ddlProviders";
private const string ProvidersLabelControlId = "lblProviders";
private const string SitesControlId = "ddlSites";
private const string SitesLabelControlId = "lblSites";
private const string ClassesControlId = "ddlClasses";
private const string ClassesLabelControlId = "lblClasses";
#endregion
}
}
back on change, but their events won't raise. Can anyone tell me whats going
on? I tried to use the IPostBackDataHandler to try to get a hold of the
control to set values and such, but it has been no help. I'm confused at how
this control is supposed to work. I want it to be self contained so that
when a control changes, it posts back and then reloads its dependent drop
down lists with data that is filtered based on the value of the control that
changed.
Every time the page posts back to server, the it hits the init and load
events and createchildcontrols, but thats it. i can't get into the
XXX_SelectedIndexChanged events for some reason even though they are wired
to do so.
Any help will be appreaciated as i'm starting to feel dumb.
using System;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Operations.Teams.Business;
using Operations.Teams.Data;
using Operations.Teams.Reporting;
using Operations.Teams.Reporting.WebControls;
namespace Operations.Teams.Web.ReportControls
{
/// <summary>
/// Summary description for FiscalAgentHierarchy.
/// </summary>
public class FiscalAgentHierarchy : Control, IReportParameterControl,
IPostBackDataHandler
{
public FiscalAgentHierarchy()
{
Parameters.Add(new Parameter("@SchoolYear"));
Parameters.Add(new Parameter("@ReportingGroup"));
Parameters.Add(new Parameter("@FiscalAgentID"));
Parameters.Add(new Parameter("@FundingSourceID"));
Parameters.Add(new Parameter("@ProviderID"));
Parameters.Add(new Parameter("@SiteID"));
Parameters.Add(new Parameter("@ClassID"));
Parameters["@SchoolYear"].Value = 2006;
}
#region Events
public bool LoadPostData(string postDataKey, NameValueCollection postData)
{
string postedValue = postData[postDataKey];
return true;
}
public void RaisePostDataChangedEvent()
{
rysReportingYearSelector_ReportingYearChanged(this, EventArgs.Empty);
}
protected override void LoadViewState(object savedState)
{
string zasdf="asdlfkjds";
}
protected override object SaveViewState()
{
string zsad="asdf";
}
protected override void OnInit(EventArgs e)
{
//this.EnsureChildControls();
// Do whatever the control usually does OnInit
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
//this.EnsureChildControls();
// Do whatever the control usually does OnInit
base.OnLoad(e);
}
private void rysReportingYearSelector_ReportingYearChanged(object sender,
EventArgs e)
{
this.LoadFundingSource();
this.LoadProviders();
}
private void fasFiscalAgent_FiscalAgentChanged(object sender, EventArgs e)
{
this.LoadFundingSource();
this.LoadProviders();
}
private void ddlProviders_SelectedIndexChanged(object sender, EventArgs e)
{
LoadSites();
}
private void ddlSites_SelectedIndexChanged(object sender, EventArgs e)
{
LoadClasses();
}
#endregion
protected override void CreateChildControls()
{
rysReportingYearSelector = new ReportingYearReportSelector();
fasFiscalAgent = new FiscalAgentReportSelector();
this.ddlFundingSource = new DropDownList();
this.ddlProviders = new DropDownList();
this.ddlSites = new DropDownList();
this.ddlClasses = new DropDownList();
rysReportingYearSelector.ID = ReportingYearSelectorControlId;
fasFiscalAgent.ID = FiscalAgentSelectorControlId;
ddlFundingSource.ID = FundingSourceControlId;
ddlProviders.ID = ProvidersControlId;
ddlSites.ID = SitesControlId;
ddlClasses.ID = ClassesControlId;
// Assign these controls' Page property because when they try to access Page
they get null reference - apparently they aren't in the control tree at that
point
rysReportingYearSelector.Page = this.Page;
fasFiscalAgent.Page = this.Page;
rysReportingYearSelector.ReportingYearChanged += new
EventHandler(rysReportingYearSelector_ReportingYearChanged);
fasFiscalAgent.FiscalAgentChanged += new
EventHandler(fasFiscalAgent_FiscalAgentChanged);
ddlProviders.SelectedIndexChanged += new
EventHandler(ddlProviders_SelectedIndexChanged);
ddlSites.SelectedIndexChanged += new
EventHandler(ddlSites_SelectedIndexChanged);
fasFiscalAgent.IsSubmitOnChange = true;
ddlProviders.AutoPostBack = true;
ddlSites.AutoPostBack = true;
// this.SchoolYear = rysReportingYearSelector.SchoolYear;
// check if can populate funding sources and providers (because fiscalAgent
has been saved in session)
if(this.fasFiscalAgent.SelectedFiscalAgentName != string.Empty)
{
LoadFundingSource();
LoadProviders();
}
else
{
ddlFundingSource.Visible = false;
ddlProviders.Visible = false;
}
// Initially set to false until their direct parent's selection has been
made (all other controls will have data on page load)
ddlSites.Visible = false;
ddlClasses.Visible = false;
// start containing table
this.Controls.Add(WebHelper.MakeLiteral("<table cellpadding=0
cellspacing=0><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>"));
this.Controls.Add(rysReportingYearSelector);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>"));
this.Controls.Add(fasFiscalAgent);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Funding
Source</td><td>"));
this.Controls.Add(ddlFundingSource);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Providers</td><td>")
);
this.Controls.Add(ddlProviders);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Sites</td><td>"));
this.Controls.Add(ddlSites);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Classes</td><td>"));
this.Controls.Add(ddlClasses);
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
// end containing table
this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
}
private void LoadFundingSource()
{
int fiscalAgentId = this.fasFiscalAgent.SelectedFiscalAgentId;
if(fiscalAgentId != int.MinValue)
{
this.ddlFundingSource.Visible = true;
this.ddlFundingSource.DataSource = FiscalAgentFunding.Find(fiscalAgentId);
this.ddlFundingSource.DataTextField = "ShortDescription";
this.ddlFundingSource.DataValueField = "CodeId";
this.ddlFundingSource.DataBind();
if(this.ddlFundingSource.Items.Count > 1)
this.ddlFundingSource.Items.Insert(0, new ListItem(string.Empty,
string.Empty));
}
else
{
this.ddlFundingSource.Visible = false;
}
}
private void LoadProviders()
{
int fiscalAgentId = fasFiscalAgent.SelectedFiscalAgentId;
if(fiscalAgentId != int.MinValue)
{
ddlProviders.Visible = true;
ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
rysReportingYearSelector.ReportingYearStartDate,
rysReportingYearSelector.ReportingYearEndDate);
ddlProviders.DataTextField = "ProviderName";
ddlProviders.DataValueField = "ProviderId";
ddlProviders.DataBind();
ddlProviders.Items.Insert(0, new ListItem(string.Empty, string.Empty));
}
else
{
this.ddlProviders.Items.Clear();
this.ddlProviders.Visible = false;
}
LoadSites();
}
private void LoadSites()
{
if(ddlProviders.SelectedValue != string.Empty)
{
// Load the Site search parameters.
SiteFindArgs siteFindArgs=new SiteFindArgs();
siteFindArgs.FiscalAgentId=Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgen
tId);
ddlSites.Visible = true;
ddlSites.DataSource = Business.Site.Find(siteFindArgs);
ddlSites.DataTextField = "Name";
ddlSites.DataValueField = "SiteId";
ddlSites.DataBind();
ddlSites.Items.Insert(0, new ListItem(string.Empty, string.Empty));
}
else
{
ddlSites.Items.Clear();
ddlSites.Visible = false;
}
LoadClasses();
}
private void LoadClasses()
{
if(ddlSites.SelectedValue != string.Empty)
{
ClassFindArgs adultEdClassFindArgs = new ClassFindArgs();
adultEdClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
adultEdClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;
adultEdClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;
adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;
adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
ddlClasses.Visible = true;
ddlClasses.DataSource = Class.Find(classFindArgs);
ddlClasses.DataTextField = "Name";
ddlClasses.DataValueField = "ClassId";
ddlClasses.DataBind();
ddlClasses.Items.Insert(0, new ListItem(string.Empty, string.Empty));
}
else
{
ddlClasses.Items.Clear();
ddlClasses.Visible = false;
}
}
#region Public Properties
#region IReportParameterControl Members
public object ParameterValue
{
get{ return null; }
set{ /*do nothing */ }
}
public ParameterCollection Parameters
{
get{ return parameters; }
set{ parameters = value;}
}
#endregion
public int SchoolYear
{
get{ return (int) ViewState["SchoolYear"]; }
set{ ViewState["SchoolYear"] = value; }
}
#endregion
#region Private Member Variables
private ReportingYearReportSelector rysReportingYearSelector;
private FiscalAgentReportSelector fasFiscalAgent;
private DropDownList ddlFundingSource;
private DropDownList ddlProviders;
private DropDownList ddlSites;
private DropDownList ddlClasses;
private ParameterCollection parameters = new ParameterCollection();
#endregion
#region Private Constants
private const string ReportingYearSelectorControlId =
"rysReportingYearSelector";
private const string FiscalAgentSelectorControlId =
"fasFiscalAgentSelector";
private const string FundingSourceControlId = "ddlFundingSource";
private const string FundingSourceLabelControlId = "lblFundingSource";
private const string ProvidersControlId = "ddlProviders";
private const string ProvidersLabelControlId = "lblProviders";
private const string SitesControlId = "ddlSites";
private const string SitesLabelControlId = "lblSites";
private const string ClassesControlId = "ddlClasses";
private const string ClassesLabelControlId = "lblClasses";
#endregion
}
}