explanation of when need to repopulate control

T

TS

I have a quesiton:
if i have a composite control and on its intial page loading, i fill my (sub
control) drop down list's items collection from the database and return.
When the user hits a button to cause postback, the control is going to get
initialized, then does its items collection that i filled on the initial
page request get repopulated from viewstate? And on top of that, if so, does
the list item that person selected in the drop down list again set itself as
the selected item in the list?

OR do i have to re-load the items on every page request and then populate
its value some other way???

thanks a bunch
 
T

TS

My control's sub control (dropdownlist) doesn't have its items collection
re-populated from viewstate. I also have a textbox that doesn't have its
value persisted either (Well sort of. In the load event, i access the
textbox and its value is blank, but when the control comes back to the user,
the value i entered in that textbox is there!!!???)

sorry for the large amount of code, but here it goes, again.
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,
INamingContainer

{

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

protected override void OnInit(EventArgs e)

{

EnsureChildControls();

if(this.fasFiscalAgent.SelectedFiscalAgentName != string.Empty)

{

if(!Page.IsPostBack)

{

LoadFundingSource();

LoadProviders();

}

}

base.OnInit (e);

}

protected override void OnLoad(EventArgs e)

{

// The controls should now be in the control tree and its client values
should be in it???

base.OnLoad (e);

}



private void rysReportingYearSelector_ReportingYearChanged(object sender,
EventArgs e)

{

this.SchoolYear = rysReportingYearSelector.SchoolYear;

this.ReportingYearGroupID = rysReportingYearSelector.ReportYearGroupId;

this.LoadFundingSource();

this.LoadProviders();

}

private void fasFiscalAgent_FiscalAgentChanged(object sender, EventArgs e)

{

this.FiscalAgentID = fasFiscalAgent.SelectedFiscalAgentId;

this.LoadFundingSource();

this.LoadProviders();

}

private void ddlProviders_SelectedIndexChanged(object sender, EventArgs e)

{

if(ddlProviders.SelectedValue != string.Empty)

this.ProviderID = Convert.ToInt32(ddlProviders.SelectedValue);

LoadSites();

}

private void ddlSites_SelectedIndexChanged(object sender, EventArgs e)

{

if(ddlSites.SelectedValue != string.Empty)

this.SiteID = Convert.ToInt32(ddlSites.SelectedValue);

LoadClasses();

}

#endregion

TextBox box = new TextBox();

protected override void CreateChildControls()

{

box.ID = "box";

if(!Page.IsPostBack)

box.Text = "hello";

Controls.Add(box);



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)

// {

// if(!Page.IsPostBack)

// {

// 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()

{

ddlProviders.Items.Add(new ListItem("test","2"));

ddlProviders.Items.Add(new ListItem("22","3"));

ddlProviders.SelectedIndex = 0;



int fiscalAgentId = fasFiscalAgent.SelectedFiscalAgentId;

if(fiscalAgentId != int.MinValue)

{

ddlProviders.Visible = true;

// are these dates correct???????????????????????????

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)

{

OperationsClassFindArgs OperationsClassFindArgs = new
OperationsClassFindArgs();

OperationsClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

OperationsClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;

OperationsClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;

OperationsClassFindArgs.ProviderName = ddlProviders.SelectedValue;

OperationsClassFindArgs.SiteName = ddlSites.SelectedValue;


ddlClasses.Visible = true;

ddlClasses.DataSource = OperationsClass.Find(OperationsClassFindArgs);

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; }

}

public int ReportingYearGroupID

{

get{ return (int) ViewState["ReportingYearGroupID"]; }

set{ ViewState["ReportingYearGroupID"] = value; }

}

public int FiscalAgentID

{

get{ return (int) ViewState["FiscalAgentID"]; }

set{ ViewState["FiscalAgentID"] = value; }

}

public int FundingSourceID

{

get{ return (int) ViewState["FundingSourceID"]; }

set{ ViewState["FundingSourceID"] = value; }

}

public int ProviderID

{

get{ return (int) ViewState["ProviderID"]; }

set{ ViewState["ProviderID"] = value; }

}

public int SiteID

{

get{ return (int) ViewState["SiteID"]; }

set{ ViewState["SiteID"] = 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

}

}
 
T

TS

sorry, heres the scenario i'm trying to accomplish:
I have a composite control that contains 4 drop down lists. When the page
loads initially, i want the first drop down filled and the rest invisible.
When you select an item in this ddl, it posts back to the server and based
on its value, it populates its immediate child's drop down list. So now the
top ddl has a value selected and the 2nd one just has its items populated.
Then when the 2nd drop down list gets selected, it posts to the server and
its value is used to populate(filter) the items for the 3rd drop down
list...and so on for each drop down list.

Please tell me what i need to do to handle post back data and maintain state
from one postback to another while keeping the drop downlists filled and
their values persisted.

thank you again!
 
S

Steven Cheng[MSFT]

Hi TS,

See you again :), seems you're rushing in a asp.net project these days?
For the question you mentioned in this post, here are some of my
understanding and suggestions:

1. ASP.NET controls derived from Control will automatically maintain its
ViewStates according to the asp.net web page's events sequence. So for
composite control, those nested sub Controls' status (properties which be
persistd in Viewsstate ) will be store and retrieve automatically.

2. However, there're some thing we need to care when building composite
control:
#remember to implement INamingContainer for controls which will have nested
sub controls. Otherwise, even handler mapping, ViewState loading will occur
unexpectedly.

#Do remember to assign a explicit ID for each sub controls(same reason as
#1). Also, please always try best to add subcontrols in the
"CreateChildControls" method(just create control hierarchy) and put
manipulating code in postback event or PreRender event.

In addition, for your detaile scenario, I've just built a very simple demo
control which have three dropdownlists and The "Top" one will display
first(other twos invisible) and according to the top one's selection, the
"Mid" dropdownlist will be pouplated and the same when the "mid"'s
selection changed......

Here's the control's code for your reference:

=========================
[DefaultProperty("Text"),
ToolboxData("<{0}:MultiListControl runat=server></{0}:MultiListControl>")]
public class MultiListControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private string text;

private DropDownList lstTop;
private DropDownList lstMid;
private DropDownList lstBot;





protected bool MidVisible
{
get{
if(ViewState["MID_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["MID_VISIBLE"];
}

set{
TrackViewState();
ViewState["MID_VISIBLE"] = value;
}
}

protected bool BotVisible
{
get
{
if(ViewState["BOT_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["BOT_VISIBLE"];
}

set
{
TrackViewState();
ViewState["BOT_VISIBLE"] = value;
}
}


[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


protected override void CreateChildControls()
{
Controls.Clear();

Controls.Add(
new LiteralControl(
@"
<table width='100%'>
<tr><td>
"));

lstTop = new DropDownList();
lstTop.ID = "lstTop";

lstTop.Items.Add("----------");
lstTop.Items.Add("Top_Item_1");
lstTop.Items.Add("Top_Item_2");
lstTop.Items.Add("Top_Item_3");
lstTop.Items.Add("Top_Item_4");

Controls.Add(lstTop);

Controls.Add(
new LiteralControl(
@"<br/>"
));

lstMid = new DropDownList();
lstMid.ID = "lstMid";

Controls.Add(lstMid);

Controls.Add(
new LiteralControl(
@"<br/>"
));


lstBot = new DropDownList();
lstBot.ID = "lstBot";

Controls.Add(lstBot);


Controls.Add(
new LiteralControl(
@"
</td></tr>
</table>
"
));



lstTop.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstMid.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstBot.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);

lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack = true;


}


protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);

lstMid.Visible = MidVisible;
lstBot.Visible = BotVisible;
}




private void lst_SelectedIndexChanged(object sender, System.EventArgs e)
{

DropDownList lst = sender as DropDownList;

switch(lst.ID)
{
case "lstTop":

if(lst.SelectedIndex != 0)
{
lstMid.DataSource = GetSubItems(lst.SelectedValue);
lstMid.DataTextField = "Text";
lstMid.DataValueField= "Value";
lstMid.DataBind();

MidVisible = true;
}
else
{
MidVisible = BotVisible = false;
}

break;
case "lstMid":

lstBot.DataSource = GetSubItems(lst.SelectedValue);
lstBot.DataTextField = "Text";
lstBot.DataValueField= "Value";
lstBot.DataBind();

MidVisible = BotVisible = true;

break;
case "lstBot":



break;
}

Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
lst.EnableViewState);
}

#region --Helper functions---

public ListItemCollection GetSubItems(string parent)
{
ListItemCollection items = new ListItemCollection();
int count = parent.Length;

for(int i=0;i<count;++i)
{
items.Add(parent + "_Item_" + i);
}

return items;
}


#endregion
}

========================
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Tue, 2 Aug 2005 18:32:23 -0500
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
..framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| sorry, heres the scenario i'm trying to accomplish:
| I have a composite control that contains 4 drop down lists. When the page
| loads initially, i want the first drop down filled and the rest invisible.
| When you select an item in this ddl, it posts back to the server and based
| on its value, it populates its immediate child's drop down list. So now
the
| top ddl has a value selected and the 2nd one just has its items populated.
| Then when the 2nd drop down list gets selected, it posts to the server and
| its value is used to populate(filter) the items for the 3rd drop down
| list...and so on for each drop down list.
|
| Please tell me what i need to do to handle post back data and maintain
state
| from one postback to another while keeping the drop downlists filled and
| their values persisted.
|
| thank you again!
|
|
| | > I have a quesiton:
| > if i have a composite control and on its intial page loading, i fill my
| (sub
| > control) drop down list's items collection from the database and return.
| > When the user hits a button to cause postback, the control is going to
get
| > initialized, then does its items collection that i filled on the initial
| > page request get repopulated from viewstate? And on top of that, if so,
| does
| > the list item that person selected in the drop down list again set
itself
| as
| > the selected item in the list?
| >
| > OR do i have to re-load the items on every page request and then
populate
| > its value some other way???
| >
| > thanks a bunch
| >
| >
|
|
|
 
T

TS

Thanks a bunch Steven I have gotten a lot of progress. I can always count on
you. I now have a new problem. The composite controls in my composite
control correctly fires their sub drop down lists which gets handled in my
main composite control. Then I have 4 drop down lists in my composite
control, and none of their selectedIndexChanged events fire.

I'm pretty sure i have all my bases covered and don't know what the problem
could be. Both sub composite controls use INamingContainter and set their
control's Id property.

Any other thoughts?

thanks

My latest code:
using System;

using System.Collections.Specialized;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text;

using OperationsTeams.Business;

using OperationsTeams.Data;

using OperationsTeams.Reporting;

using OperationsTeams.Reporting.WebControls;

namespace OperationsTeams.Web.ReportControls

{

/// <summary>

/// Summary description for FiscalAgentHierarchy.

/// </summary>

public class FiscalAgentHierarchy : WebControl, IReportParameterControl,
INamingContainer

{

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

protected override void OnPreRender(EventArgs e)

{

base.OnPreRender (e);

// The controls now have the client values from the the last postback

ddlFundingSource.Visible = FundingSourceVisible;

ddlProviders.Visible = ProviderVisible;

ddlSites.Visible = SiteVisible;

ddlClasses.Visible = ClassVisible;

}

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 ddlFundingSource_SelectedIndexChanged(object sender, EventArgs
e)

{

LoadSites();

}

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;


// 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)

{

FundingSourceVisible = 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

{

FundingSourceVisible = false;

}

}

private void LoadProviders()

{

int fiscalAgentId = fasFiscalAgent.SelectedFiscalAgentId;

if(fiscalAgentId != int.MinValue)

{

ProviderVisible = true;

// are these dates correct???????????????????????????

ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
rysReportingYearSelector.ReportingYearStartDate,
rysReportingYearSelector.ReportingYearEndDate); //new DateTime(2005,7,1),
new DateTime(2006,6,30));

ddlProviders.DataTextField = "ProviderName";

ddlProviders.DataValueField = "ProviderId";

ddlProviders.DataBind();

ddlProviders.Items.Insert(0, new ListItem(string.Empty, string.Empty));

}

else

{

this.ddlProviders.Items.Clear();

ProviderVisible = false;

}

}

private void LoadSites()

{

if(ddlProviders.SelectedValue != string.Empty)

{

// Load the Site search parameters.

SiteFindArgs siteFindArgs=new SiteFindArgs();

siteFindArgs.FiscalAgentId=Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgen
tId);

SiteVisible = 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();

SiteVisible = false;

}

}

private void LoadClasses()

{

if(ddlSites.SelectedValue != string.Empty)

{

AdultEdClassFindArgs adultEdClassFindArgs = new AdultEdClassFindArgs();

adultEdClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

adultEdClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;

adultEdClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;

adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;

adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;


ClassVisible = true;

ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);

ddlClasses.DataTextField = "Name";

ddlClasses.DataValueField = "ClassId";

ddlClasses.DataBind();

ddlClasses.Items.Insert(0, new ListItem(string.Empty, string.Empty));

}

else

{

ddlClasses.Items.Clear();

ClassVisible = 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

protected bool FundingSourceVisible

{

get

{

if(ViewState["FundingSourceVisible"] == null)

{

return false;

}

return (bool)ViewState["FundingSourceVisible"];

}

set

{

TrackViewState();

ViewState["FundingSourceVisible"] = value;

}

}

protected bool ProviderVisible

{

get

{

if(ViewState["ProviderVisible"] == null)

{

return false;

}

return (bool)ViewState["ProviderVisible"];

}

set

{

TrackViewState();

ViewState["ProviderVisible"] = value;

}

}

protected bool SiteVisible

{

get

{

if(ViewState["SiteVisible"] == null)

{

return false;

}

return (bool)ViewState["SiteVisible"];

}

set

{

TrackViewState();

ViewState["SiteVisible"] = value;

}

}

protected bool ClassVisible

{

get

{

if(ViewState["ClassVisible"] == null)

{

return false;

}

return (bool)ViewState["ClassVisible"];

}

set

{

TrackViewState();

ViewState["ClassVisible"] = 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

}

}


Steven Cheng said:
Hi TS,

See you again :), seems you're rushing in a asp.net project these days?
For the question you mentioned in this post, here are some of my
understanding and suggestions:

1. ASP.NET controls derived from Control will automatically maintain its
ViewStates according to the asp.net web page's events sequence. So for
composite control, those nested sub Controls' status (properties which be
persistd in Viewsstate ) will be store and retrieve automatically.

2. However, there're some thing we need to care when building composite
control:
#remember to implement INamingContainer for controls which will have nested
sub controls. Otherwise, even handler mapping, ViewState loading will occur
unexpectedly.

#Do remember to assign a explicit ID for each sub controls(same reason as
#1). Also, please always try best to add subcontrols in the
"CreateChildControls" method(just create control hierarchy) and put
manipulating code in postback event or PreRender event.

In addition, for your detaile scenario, I've just built a very simple demo
control which have three dropdownlists and The "Top" one will display
first(other twos invisible) and according to the top one's selection, the
"Mid" dropdownlist will be pouplated and the same when the "mid"'s
selection changed......

Here's the control's code for your reference:

=========================
[DefaultProperty("Text"),
ToolboxData("<{0}:MultiListControl runat=server></{0}:MultiListControl>")]
public class MultiListControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private string text;

private DropDownList lstTop;
private DropDownList lstMid;
private DropDownList lstBot;





protected bool MidVisible
{
get{
if(ViewState["MID_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["MID_VISIBLE"];
}

set{
TrackViewState();
ViewState["MID_VISIBLE"] = value;
}
}

protected bool BotVisible
{
get
{
if(ViewState["BOT_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["BOT_VISIBLE"];
}

set
{
TrackViewState();
ViewState["BOT_VISIBLE"] = value;
}
}


[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


protected override void CreateChildControls()
{
Controls.Clear();

Controls.Add(
new LiteralControl(
@"
<table width='100%'>
<tr><td>
"));

lstTop = new DropDownList();
lstTop.ID = "lstTop";

lstTop.Items.Add("----------");
lstTop.Items.Add("Top_Item_1");
lstTop.Items.Add("Top_Item_2");
lstTop.Items.Add("Top_Item_3");
lstTop.Items.Add("Top_Item_4");

Controls.Add(lstTop);

Controls.Add(
new LiteralControl(
@"<br/>"
));

lstMid = new DropDownList();
lstMid.ID = "lstMid";

Controls.Add(lstMid);

Controls.Add(
new LiteralControl(
@"<br/>"
));


lstBot = new DropDownList();
lstBot.ID = "lstBot";

Controls.Add(lstBot);


Controls.Add(
new LiteralControl(
@"
</td></tr>
</table>
"
));



lstTop.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstMid.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstBot.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);

lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack = true;


}


protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);

lstMid.Visible = MidVisible;
lstBot.Visible = BotVisible;
}




private void lst_SelectedIndexChanged(object sender, System.EventArgs e)
{

DropDownList lst = sender as DropDownList;

switch(lst.ID)
{
case "lstTop":

if(lst.SelectedIndex != 0)
{
lstMid.DataSource = GetSubItems(lst.SelectedValue);
lstMid.DataTextField = "Text";
lstMid.DataValueField= "Value";
lstMid.DataBind();

MidVisible = true;
}
else
{
MidVisible = BotVisible = false;
}

break;
case "lstMid":

lstBot.DataSource = GetSubItems(lst.SelectedValue);
lstBot.DataTextField = "Text";
lstBot.DataValueField= "Value";
lstBot.DataBind();

MidVisible = BotVisible = true;

break;
case "lstBot":



break;
}

Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
lst.EnableViewState);
}

#region --Helper functions---

public ListItemCollection GetSubItems(string parent)
{
ListItemCollection items = new ListItemCollection();
int count = parent.Length;

for(int i=0;i<count;++i)
{
items.Add(parent + "_Item_" + i);
}

return items;
}


#endregion
}

========================
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Tue, 2 Aug 2005 18:32:23 -0500
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| sorry, heres the scenario i'm trying to accomplish:
| I have a composite control that contains 4 drop down lists. When the page
| loads initially, i want the first drop down filled and the rest invisible.
| When you select an item in this ddl, it posts back to the server and based
| on its value, it populates its immediate child's drop down list. So now
the
| top ddl has a value selected and the 2nd one just has its items populated.
| Then when the 2nd drop down list gets selected, it posts to the server and
| its value is used to populate(filter) the items for the 3rd drop down
| list...and so on for each drop down list.
|
| Please tell me what i need to do to handle post back data and maintain
state
| from one postback to another while keeping the drop downlists filled and
| their values persisted.
|
| thank you again!
|
|
| | > I have a quesiton:
| > if i have a composite control and on its intial page loading, i fill my
| (sub
| > control) drop down list's items collection from the database and return.
| > When the user hits a button to cause postback, the control is going to
get
| > initialized, then does its items collection that i filled on the initial
| > page request get repopulated from viewstate? And on top of that, if so,
| does
| > the list item that person selected in the drop down list again set
itself
| as
| > the selected item in the list?
| >
| > OR do i have to re-load the items on every page request and then
populate
| > its value some other way???
| >
| > thanks a bunch
| >
| >
|
|
|
 
T

TS

Another problem:

while i'm waiting on your remark to my last post, i removed the sub
composite controls from my composite control so that there is only drop down
lists on it. During CreateChildcontrols, i load the main drop down using
databind. When the page is sent to browser for the first time, i have my
main drop down filled. I then select an item and its SelectedIndexChanged
fires and populates the send drop down list. Then when i select an item from
it, it posts back, and the event that gets called is the main(first)
dropdown list's SelectedIndexChanged event, which then re-populates the
second drop down list, then the control returns to the browser (The
SelectedIndexChanged event never fired for the 2nd dropdown's changed
event.???

thanks again

using System;

using System.Collections.Specialized;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text;

using OperationsTeams.Business;

using OperationsTeams.Data;

using OperationsTeams.Reporting;

using OperationsTeams.Reporting.WebControls;

namespace OperationsTeams.Web.ReportControls

{

/// <summary>

/// Summary description for FiscalAgentHierarchy.

/// </summary>

public class FiscalAgentHierarchy : WebControl, IReportParameterControl,
INamingContainer

{

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

protected override void OnLoad(EventArgs e)

{

base.OnLoad (e);


// The last state of controls from viewstate is now loaded (Before the
client data is processed)

}


protected override void OnPreRender(EventArgs e)

{

base.OnPreRender (e);

// The controls now have the client values from the the last postback

// ddlFundingSource.Visible = FundingSourceVisible;

// ddlProviders.Visible = ProviderVisible;

// ddlSites.Visible = SiteVisible;

// ddlClasses.Visible = ClassVisible;

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));

// ddlSites.Visible = true;

}

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 ddlFundingSource_SelectedIndexChanged(object sender, EventArgs
e)

{

LoadSites();

}

private void ddlProviders_SelectedIndexChanged(object sender, EventArgs e)

{

LoadSites();

}

private void ddlSites_SelectedIndexChanged(object sender, EventArgs e)

{

LoadClasses();

}

#endregion

protected override void CreateChildControls()

{

this.ddlFundingSource = new DropDownList();

this.ddlProviders = new DropDownList();

this.ddlSites = new DropDownList();

this.ddlClasses = new DropDownList();

ddlFundingSource.ID = FundingSourceControlId;

ddlProviders.ID = ProvidersControlId;

ddlSites.ID = SitesControlId;

ddlClasses.ID = ClassesControlId;


LoadProviders();

// 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>"));

ddlFundingSource.SelectedIndexChanged += new
EventHandler(ddlFundingSource_SelectedIndexChanged);

ddlProviders.SelectedIndexChanged += new
EventHandler(ddlProviders_SelectedIndexChanged);

ddlSites.SelectedIndexChanged += new
EventHandler(ddlSites_SelectedIndexChanged);

ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
ddlSites.AutoPostBack = true;


}

private void LoadFundingSource()

{

int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;


if(fiscalAgentId != int.MinValue)

{

FundingSourceVisible = 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

{

FundingSourceVisible = false;

}

}

private void LoadProviders()

{

int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;

if(fiscalAgentId != int.MinValue)

{

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));



ProviderVisible = true;

// are these dates correct???????????????????????????

ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId, new
DateTime(2005,7,1), new
DateTime(2006,6,30));//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();

ProviderVisible = false;

}

// LoadSites();

}

private void LoadSites()

{

if(ddlProviders.SelectedValue != string.Empty)

{

// Load the Site search parameters.

SiteFindArgs siteFindArgs=new SiteFindArgs();

siteFindArgs.FiscalAgentId=1;
//Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

SiteVisible = 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();

SiteVisible = false;

}

// LoadClasses();

}

private void LoadClasses()

{

if(ddlSites.SelectedValue != string.Empty)

{

AdultEdClassFindArgs adultEdClassFindArgs = new AdultEdClassFindArgs();

// adultEdClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

// adultEdClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;

// adultEdClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;

// adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;

// adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;


ClassVisible = true;

ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);

ddlClasses.DataTextField = "Name";

ddlClasses.DataValueField = "ClassId";

ddlClasses.DataBind();

ddlClasses.Items.Insert(0, new ListItem(string.Empty, string.Empty));

}

else

{

ddlClasses.Items.Clear();

ClassVisible = 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

protected bool FundingSourceVisible

{

get

{

if(ViewState["FundingSourceVisible"] == null)

{

return false;

}

return (bool)ViewState["FundingSourceVisible"];

}

set

{

TrackViewState();

ViewState["FundingSourceVisible"] = value;

}

}

protected bool ProviderVisible

{

get

{

if(ViewState["ProviderVisible"] == null)

{

return false;

}

return (bool)ViewState["ProviderVisible"];

}

set

{

TrackViewState();

ViewState["ProviderVisible"] = value;

}

}

protected bool SiteVisible

{

get

{

if(ViewState["SiteVisible"] == null)

{

return false;

}

return (bool)ViewState["SiteVisible"];

}

set

{

TrackViewState();

ViewState["SiteVisible"] = value;

}

}

protected bool ClassVisible

{

get

{

if(ViewState["ClassVisible"] == null)

{

return false;

}

return (bool)ViewState["ClassVisible"];

}

set

{

TrackViewState();

ViewState["ClassVisible"] = value;

}

}

#endregion

#region Private Member Variables

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

}

}


Steven Cheng said:
Hi TS,

See you again :), seems you're rushing in a asp.net project these days?
For the question you mentioned in this post, here are some of my
understanding and suggestions:

1. ASP.NET controls derived from Control will automatically maintain its
ViewStates according to the asp.net web page's events sequence. So for
composite control, those nested sub Controls' status (properties which be
persistd in Viewsstate ) will be store and retrieve automatically.

2. However, there're some thing we need to care when building composite
control:
#remember to implement INamingContainer for controls which will have nested
sub controls. Otherwise, even handler mapping, ViewState loading will occur
unexpectedly.

#Do remember to assign a explicit ID for each sub controls(same reason as
#1). Also, please always try best to add subcontrols in the
"CreateChildControls" method(just create control hierarchy) and put
manipulating code in postback event or PreRender event.

In addition, for your detaile scenario, I've just built a very simple demo
control which have three dropdownlists and The "Top" one will display
first(other twos invisible) and according to the top one's selection, the
"Mid" dropdownlist will be pouplated and the same when the "mid"'s
selection changed......

Here's the control's code for your reference:

=========================
[DefaultProperty("Text"),
ToolboxData("<{0}:MultiListControl runat=server></{0}:MultiListControl>")]
public class MultiListControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private string text;

private DropDownList lstTop;
private DropDownList lstMid;
private DropDownList lstBot;





protected bool MidVisible
{
get{
if(ViewState["MID_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["MID_VISIBLE"];
}

set{
TrackViewState();
ViewState["MID_VISIBLE"] = value;
}
}

protected bool BotVisible
{
get
{
if(ViewState["BOT_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["BOT_VISIBLE"];
}

set
{
TrackViewState();
ViewState["BOT_VISIBLE"] = value;
}
}


[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


protected override void CreateChildControls()
{
Controls.Clear();

Controls.Add(
new LiteralControl(
@"
<table width='100%'>
<tr><td>
"));

lstTop = new DropDownList();
lstTop.ID = "lstTop";

lstTop.Items.Add("----------");
lstTop.Items.Add("Top_Item_1");
lstTop.Items.Add("Top_Item_2");
lstTop.Items.Add("Top_Item_3");
lstTop.Items.Add("Top_Item_4");

Controls.Add(lstTop);

Controls.Add(
new LiteralControl(
@"<br/>"
));

lstMid = new DropDownList();
lstMid.ID = "lstMid";

Controls.Add(lstMid);

Controls.Add(
new LiteralControl(
@"<br/>"
));


lstBot = new DropDownList();
lstBot.ID = "lstBot";

Controls.Add(lstBot);


Controls.Add(
new LiteralControl(
@"
</td></tr>
</table>
"
));



lstTop.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstMid.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstBot.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);

lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack = true;


}


protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);

lstMid.Visible = MidVisible;
lstBot.Visible = BotVisible;
}




private void lst_SelectedIndexChanged(object sender, System.EventArgs e)
{

DropDownList lst = sender as DropDownList;

switch(lst.ID)
{
case "lstTop":

if(lst.SelectedIndex != 0)
{
lstMid.DataSource = GetSubItems(lst.SelectedValue);
lstMid.DataTextField = "Text";
lstMid.DataValueField= "Value";
lstMid.DataBind();

MidVisible = true;
}
else
{
MidVisible = BotVisible = false;
}

break;
case "lstMid":

lstBot.DataSource = GetSubItems(lst.SelectedValue);
lstBot.DataTextField = "Text";
lstBot.DataValueField= "Value";
lstBot.DataBind();

MidVisible = BotVisible = true;

break;
case "lstBot":



break;
}

Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
lst.EnableViewState);
}

#region --Helper functions---

public ListItemCollection GetSubItems(string parent)
{
ListItemCollection items = new ListItemCollection();
int count = parent.Length;

for(int i=0;i<count;++i)
{
items.Add(parent + "_Item_" + i);
}

return items;
}


#endregion
}

========================
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Tue, 2 Aug 2005 18:32:23 -0500
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| sorry, heres the scenario i'm trying to accomplish:
| I have a composite control that contains 4 drop down lists. When the page
| loads initially, i want the first drop down filled and the rest invisible.
| When you select an item in this ddl, it posts back to the server and based
| on its value, it populates its immediate child's drop down list. So now
the
| top ddl has a value selected and the 2nd one just has its items populated.
| Then when the 2nd drop down list gets selected, it posts to the server and
| its value is used to populate(filter) the items for the 3rd drop down
| list...and so on for each drop down list.
|
| Please tell me what i need to do to handle post back data and maintain
state
| from one postback to another while keeping the drop downlists filled and
| their values persisted.
|
| thank you again!
|
|
| | > I have a quesiton:
| > if i have a composite control and on its intial page loading, i fill my
| (sub
| > control) drop down list's items collection from the database and return.
| > When the user hits a button to cause postback, the control is going to
get
| > initialized, then does its items collection that i filled on the initial
| > page request get repopulated from viewstate? And on top of that, if so,
| does
| > the list item that person selected in the drop down list again set
itself
| as
| > the selected item in the list?
| >
| > OR do i have to re-load the items on every page request and then
populate
| > its value some other way???
| >
| > thanks a bunch
| >
| >
|
|
|
 
T

TS

In testing, i removed the main parent dropdown and only left the 2 below it.
this time, the same scenario happened...when the child dropdown list
autopostsback, it's immediate parent's selectedindexchanged event fires! I'm
starting to pull my hair out now...I"m stuck!

please help superman

TS said:
Another problem:

while i'm waiting on your remark to my last post, i removed the sub
composite controls from my composite control so that there is only drop down
lists on it. During CreateChildcontrols, i load the main drop down using
databind. When the page is sent to browser for the first time, i have my
main drop down filled. I then select an item and its SelectedIndexChanged
fires and populates the send drop down list. Then when i select an item from
it, it posts back, and the event that gets called is the main(first)
dropdown list's SelectedIndexChanged event, which then re-populates the
second drop down list, then the control returns to the browser (The
SelectedIndexChanged event never fired for the 2nd dropdown's changed
event.???

thanks again

using System;

using System.Collections.Specialized;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text;

using OperationsTeams.Business;

using OperationsTeams.Data;

using OperationsTeams.Reporting;

using OperationsTeams.Reporting.WebControls;

namespace OperationsTeams.Web.ReportControls

{

/// <summary>

/// Summary description for FiscalAgentHierarchy.

/// </summary>

public class FiscalAgentHierarchy : WebControl, IReportParameterControl,
INamingContainer

{

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

protected override void OnLoad(EventArgs e)

{

base.OnLoad (e);


// The last state of controls from viewstate is now loaded (Before the
client data is processed)

}


protected override void OnPreRender(EventArgs e)

{

base.OnPreRender (e);

// The controls now have the client values from the the last postback

// ddlFundingSource.Visible = FundingSourceVisible;

// ddlProviders.Visible = ProviderVisible;

// ddlSites.Visible = SiteVisible;

// ddlClasses.Visible = ClassVisible;

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));

// ddlSites.Visible = true;

}

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 ddlFundingSource_SelectedIndexChanged(object sender, EventArgs
e)

{

LoadSites();

}

private void ddlProviders_SelectedIndexChanged(object sender, EventArgs e)

{

LoadSites();

}

private void ddlSites_SelectedIndexChanged(object sender, EventArgs e)

{

LoadClasses();

}

#endregion

protected override void CreateChildControls()

{

this.ddlFundingSource = new DropDownList();

this.ddlProviders = new DropDownList();

this.ddlSites = new DropDownList();

this.ddlClasses = new DropDownList();

ddlFundingSource.ID = FundingSourceControlId;

ddlProviders.ID = ProvidersControlId;

ddlSites.ID = SitesControlId;

ddlClasses.ID = ClassesControlId;


LoadProviders();

// 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( said:
);

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( said:
this.Controls.Add(ddlClasses);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

// end containing table

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

ddlFundingSource.SelectedIndexChanged += new
EventHandler(ddlFundingSource_SelectedIndexChanged);

ddlProviders.SelectedIndexChanged += new
EventHandler(ddlProviders_SelectedIndexChanged);

ddlSites.SelectedIndexChanged += new
EventHandler(ddlSites_SelectedIndexChanged);

ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
ddlSites.AutoPostBack = true;


}

private void LoadFundingSource()

{

int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;


if(fiscalAgentId != int.MinValue)

{

FundingSourceVisible = 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

{

FundingSourceVisible = false;

}

}

private void LoadProviders()

{

int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;

if(fiscalAgentId != int.MinValue)

{

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));



ProviderVisible = true;

// are these dates correct???????????????????????????

ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId, new
DateTime(2005,7,1), new
DateTime(2006,6,30));//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();

ProviderVisible = false;

}

// LoadSites();

}

private void LoadSites()

{

if(ddlProviders.SelectedValue != string.Empty)

{

// Load the Site search parameters.

SiteFindArgs siteFindArgs=new SiteFindArgs();

siteFindArgs.FiscalAgentId=1;
//Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

SiteVisible = 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();

SiteVisible = false;

}

// LoadClasses();

}

private void LoadClasses()

{

if(ddlSites.SelectedValue != string.Empty)

{

AdultEdClassFindArgs adultEdClassFindArgs = new AdultEdClassFindArgs();

// adultEdClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

// adultEdClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;

// adultEdClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;

// adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;

// adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;


ClassVisible = true;

ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);

ddlClasses.DataTextField = "Name";

ddlClasses.DataValueField = "ClassId";

ddlClasses.DataBind();

ddlClasses.Items.Insert(0, new ListItem(string.Empty, string.Empty));

}

else

{

ddlClasses.Items.Clear();

ClassVisible = 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

protected bool FundingSourceVisible

{

get

{

if(ViewState["FundingSourceVisible"] == null)

{

return false;

}

return (bool)ViewState["FundingSourceVisible"];

}

set

{

TrackViewState();

ViewState["FundingSourceVisible"] = value;

}

}

protected bool ProviderVisible

{

get

{

if(ViewState["ProviderVisible"] == null)

{

return false;

}

return (bool)ViewState["ProviderVisible"];

}

set

{

TrackViewState();

ViewState["ProviderVisible"] = value;

}

}

protected bool SiteVisible

{

get

{

if(ViewState["SiteVisible"] == null)

{

return false;

}

return (bool)ViewState["SiteVisible"];

}

set

{

TrackViewState();

ViewState["SiteVisible"] = value;

}

}

protected bool ClassVisible

{

get

{

if(ViewState["ClassVisible"] == null)

{

return false;

}

return (bool)ViewState["ClassVisible"];

}

set

{

TrackViewState();

ViewState["ClassVisible"] = value;

}

}

#endregion

#region Private Member Variables

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

}

}


Steven Cheng said:
Hi TS,

See you again :), seems you're rushing in a asp.net project these days?
For the question you mentioned in this post, here are some of my
understanding and suggestions:

1. ASP.NET controls derived from Control will automatically maintain its
ViewStates according to the asp.net web page's events sequence. So for
composite control, those nested sub Controls' status (properties which be
persistd in Viewsstate ) will be store and retrieve automatically.

2. However, there're some thing we need to care when building composite
control:
#remember to implement INamingContainer for controls which will have nested
sub controls. Otherwise, even handler mapping, ViewState loading will occur
unexpectedly.

#Do remember to assign a explicit ID for each sub controls(same reason as
#1). Also, please always try best to add subcontrols in the
"CreateChildControls" method(just create control hierarchy) and put
manipulating code in postback event or PreRender event.

In addition, for your detaile scenario, I've just built a very simple demo
control which have three dropdownlists and The "Top" one will display
first(other twos invisible) and according to the top one's selection, the
"Mid" dropdownlist will be pouplated and the same when the "mid"'s
selection changed......

Here's the control's code for your reference:

=========================
[DefaultProperty("Text"),
ToolboxData("<{0}:MultiListControl
runat=server> said:
public class MultiListControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private string text;

private DropDownList lstTop;
private DropDownList lstMid;
private DropDownList lstBot;





protected bool MidVisible
{
get{
if(ViewState["MID_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["MID_VISIBLE"];
}

set{
TrackViewState();
ViewState["MID_VISIBLE"] = value;
}
}

protected bool BotVisible
{
get
{
if(ViewState["BOT_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["BOT_VISIBLE"];
}

set
{
TrackViewState();
ViewState["BOT_VISIBLE"] = value;
}
}


[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


protected override void CreateChildControls()
{
Controls.Clear();

Controls.Add(
new LiteralControl(
@"
<table width='100%'>
<tr><td>
"));

lstTop = new DropDownList();
lstTop.ID = "lstTop";

lstTop.Items.Add("----------");
lstTop.Items.Add("Top_Item_1");
lstTop.Items.Add("Top_Item_2");
lstTop.Items.Add("Top_Item_3");
lstTop.Items.Add("Top_Item_4");

Controls.Add(lstTop);

Controls.Add(
new LiteralControl(
@"<br/>"
));

lstMid = new DropDownList();
lstMid.ID = "lstMid";

Controls.Add(lstMid);

Controls.Add(
new LiteralControl(
@"<br/>"
));


lstBot = new DropDownList();
lstBot.ID = "lstBot";

Controls.Add(lstBot);


Controls.Add(
new LiteralControl(
@"
</td></tr>
</table>
"
));



lstTop.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstMid.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstBot.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);

lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack = true;


}


protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);

lstMid.Visible = MidVisible;
lstBot.Visible = BotVisible;
}




private void lst_SelectedIndexChanged(object sender, System.EventArgs e)
{

DropDownList lst = sender as DropDownList;

switch(lst.ID)
{
case "lstTop":

if(lst.SelectedIndex != 0)
{
lstMid.DataSource = GetSubItems(lst.SelectedValue);
lstMid.DataTextField = "Text";
lstMid.DataValueField= "Value";
lstMid.DataBind();

MidVisible = true;
}
else
{
MidVisible = BotVisible = false;
}

break;
case "lstMid":

lstBot.DataSource = GetSubItems(lst.SelectedValue);
lstBot.DataTextField = "Text";
lstBot.DataValueField= "Value";
lstBot.DataBind();

MidVisible = BotVisible = true;

break;
case "lstBot":



break;
}

Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
lst.EnableViewState);
}

#region --Helper functions---

public ListItemCollection GetSubItems(string parent)
{
ListItemCollection items = new ListItemCollection();
int count = parent.Length;

for(int i=0;i<count;++i)
{
items.Add(parent + "_Item_" + i);
}

return items;
}


#endregion
}

========================
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Tue, 2 Aug 2005 18:32:23 -0500
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| sorry, heres the scenario i'm trying to accomplish:
| I have a composite control that contains 4 drop down lists. When the page
| loads initially, i want the first drop down filled and the rest invisible.
| When you select an item in this ddl, it posts back to the server and based
| on its value, it populates its immediate child's drop down list. So now
the
| top ddl has a value selected and the 2nd one just has its items populated.
| Then when the 2nd drop down list gets selected, it posts to the server and
| its value is used to populate(filter) the items for the 3rd drop down
| list...and so on for each drop down list.
|
| Please tell me what i need to do to handle post back data and maintain
state
| from one postback to another while keeping the drop downlists filled and
| their values persisted.
|
| thank you again!
|
|
| | > I have a quesiton:
| > if i have a composite control and on its intial page loading, i fill my
| (sub
| > control) drop down list's items collection from the database and return.
| > When the user hits a button to cause postback, the control is going to
get
| > initialized, then does its items collection that i filled on the initial
| > page request get repopulated from viewstate? And on top of that, if so,
| does
| > the list item that person selected in the drop down list again set
itself
| as
| > the selected item in the list?
| >
| > OR do i have to re-load the items on every page request and then
populate
| > its value some other way???
| >
| > thanks a bunch
| >
| >
|
|
|
 
T

TS

I have figured the cause of the problem, sort of. My main control was being
loaded dynamically during a custom data list control's ItemDataBound event,
and then added to the e.item.controls collection. Once I removed it from
here, the correct event was called in my control. the problem is i need to
keep it where it is because of the way the page works.

I tried to add INamingContainer to the custom Datalist, but that didn't
help. Any ideas what could make this happen?

thanks so much, i know i'm being a pain, but i'm stuck!

This is the custom DataLists' event:
protected override void OnItemDataBound(DataListItemEventArgs e)

{

base.OnItemDataBound(e);

Parameter parameter = (Parameter)e.Item.DataItem;

try

{

Control control;

if(parameter.Type == ParameterType.Control)

control = this.Page.LoadControl(parameter.ControlPath);

else

{

Assembly assembly = parameter.Assembly;

if(assembly == null)

{

// The control didn't declare its own assembly, so use the report's
ControlsAssembly

assembly = this.ControlsAssembly;

// Ther report's ControlsAssembly is null, so use current page's assembly

if(assembly == null)

assembly = this.Page.GetType().BaseType.Assembly;

}


control = (Control) assembly.CreateInstance(parameter.ControlTypeName);

}

control.ID = parameter.Name;

// Set up all the properties of this control from the parameter.properties

foreach(DictionaryEntry de in parameter.Properties)

SetProperty(de.Key.ToString(), de.Value.ToString(), control);


e.Item.Controls.Add(control);

}

catch (Exception ex)

{

throw new ApplicationException("Unable to render criteria. Reason: " +
ex.Message, ex);

}

}

TS said:
In testing, i removed the main parent dropdown and only left the 2 below it.
this time, the same scenario happened...when the child dropdown list
autopostsback, it's immediate parent's selectedindexchanged event fires! I 'm
starting to pull my hair out now...I"m stuck!

please help superman

TS said:
Another problem:

while i'm waiting on your remark to my last post, i removed the sub
composite controls from my composite control so that there is only drop down
lists on it. During CreateChildcontrols, i load the main drop down using
databind. When the page is sent to browser for the first time, i have my
main drop down filled. I then select an item and its SelectedIndexChanged
fires and populates the send drop down list. Then when i select an item from
it, it posts back, and the event that gets called is the main(first)
dropdown list's SelectedIndexChanged event, which then re-populates the
second drop down list, then the control returns to the browser (The
SelectedIndexChanged event never fired for the 2nd dropdown's changed
event.???

thanks again

using System;

using System.Collections.Specialized;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text;

using OperationsTeams.Business;

using OperationsTeams.Data;

using OperationsTeams.Reporting;

using OperationsTeams.Reporting.WebControls;

namespace OperationsTeams.Web.ReportControls

{

/// <summary>

/// Summary description for FiscalAgentHierarchy.

/// </summary>

public class FiscalAgentHierarchy : WebControl, IReportParameterControl,
INamingContainer

{

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

protected override void OnLoad(EventArgs e)

{

base.OnLoad (e);


// The last state of controls from viewstate is now loaded (Before the
client data is processed)

}


protected override void OnPreRender(EventArgs e)

{

base.OnPreRender (e);

// The controls now have the client values from the the last postback

// ddlFundingSource.Visible = FundingSourceVisible;

// ddlProviders.Visible = ProviderVisible;

// ddlSites.Visible = SiteVisible;

// ddlClasses.Visible = ClassVisible;

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));

// ddlSites.Visible = true;

}

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 ddlFundingSource_SelectedIndexChanged(object sender, EventArgs
e)

{

LoadSites();

}

private void ddlProviders_SelectedIndexChanged(object sender, EventArgs e)

{

LoadSites();

}

private void ddlSites_SelectedIndexChanged(object sender, EventArgs e)

{

LoadClasses();

}

#endregion

protected override void CreateChildControls()

{

this.ddlFundingSource = new DropDownList();

this.ddlProviders = new DropDownList();

this.ddlSites = new DropDownList();

this.ddlClasses = new DropDownList();

ddlFundingSource.ID = FundingSourceControlId;

ddlProviders.ID = ProvidersControlId;

ddlSites.ID = SitesControlId;

ddlClasses.ID = ClassesControlId;


LoadProviders();

// 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( said:
this.Controls.Add(ddlClasses);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

// end containing table

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

ddlFundingSource.SelectedIndexChanged += new
EventHandler(ddlFundingSource_SelectedIndexChanged);

ddlProviders.SelectedIndexChanged += new
EventHandler(ddlProviders_SelectedIndexChanged);

ddlSites.SelectedIndexChanged += new
EventHandler(ddlSites_SelectedIndexChanged);

ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
ddlSites.AutoPostBack = true;


}

private void LoadFundingSource()

{

int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;


if(fiscalAgentId != int.MinValue)

{

FundingSourceVisible = 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

{

FundingSourceVisible = false;

}

}

private void LoadProviders()

{

int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;

if(fiscalAgentId != int.MinValue)

{

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));



ProviderVisible = true;

// are these dates correct???????????????????????????

ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId, new
DateTime(2005,7,1), new
DateTime(2006,6,30));//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();

ProviderVisible = false;

}

// LoadSites();

}

private void LoadSites()

{

if(ddlProviders.SelectedValue != string.Empty)

{

// Load the Site search parameters.

SiteFindArgs siteFindArgs=new SiteFindArgs();

siteFindArgs.FiscalAgentId=1;
//Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

SiteVisible = 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();

SiteVisible = false;

}

// LoadClasses();

}

private void LoadClasses()

{

if(ddlSites.SelectedValue != string.Empty)

{

AdultEdClassFindArgs adultEdClassFindArgs = new AdultEdClassFindArgs();

// adultEdClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

// adultEdClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;

// adultEdClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;

// adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;

// adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;


ClassVisible = true;

ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);

ddlClasses.DataTextField = "Name";

ddlClasses.DataValueField = "ClassId";

ddlClasses.DataBind();

ddlClasses.Items.Insert(0, new ListItem(string.Empty, string.Empty));

}

else

{

ddlClasses.Items.Clear();

ClassVisible = 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

protected bool FundingSourceVisible

{

get

{

if(ViewState["FundingSourceVisible"] == null)

{

return false;

}

return (bool)ViewState["FundingSourceVisible"];

}

set

{

TrackViewState();

ViewState["FundingSourceVisible"] = value;

}

}

protected bool ProviderVisible

{

get

{

if(ViewState["ProviderVisible"] == null)

{

return false;

}

return (bool)ViewState["ProviderVisible"];

}

set

{

TrackViewState();

ViewState["ProviderVisible"] = value;

}

}

protected bool SiteVisible

{

get

{

if(ViewState["SiteVisible"] == null)

{

return false;

}

return (bool)ViewState["SiteVisible"];

}

set

{

TrackViewState();

ViewState["SiteVisible"] = value;

}

}

protected bool ClassVisible

{

get

{

if(ViewState["ClassVisible"] == null)

{

return false;

}

return (bool)ViewState["ClassVisible"];

}

set

{

TrackViewState();

ViewState["ClassVisible"] = value;

}

}

#endregion

#region Private Member Variables

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

}

}


Steven Cheng said:
Hi TS,

See you again :), seems you're rushing in a asp.net project these days?
For the question you mentioned in this post, here are some of my
understanding and suggestions:

1. ASP.NET controls derived from Control will automatically maintain its
ViewStates according to the asp.net web page's events sequence. So for
composite control, those nested sub Controls' status (properties which be
persistd in Viewsstate ) will be store and retrieve automatically.

2. However, there're some thing we need to care when building composite
control:
#remember to implement INamingContainer for controls which will have nested
sub controls. Otherwise, even handler mapping, ViewState loading will occur
unexpectedly.

#Do remember to assign a explicit ID for each sub controls(same reason as
#1). Also, please always try best to add subcontrols in the
"CreateChildControls" method(just create control hierarchy) and put
manipulating code in postback event or PreRender event.

In addition, for your detaile scenario, I've just built a very simple demo
control which have three dropdownlists and The "Top" one will display
first(other twos invisible) and according to the top one's selection, the
"Mid" dropdownlist will be pouplated and the same when the "mid"'s
selection changed......

Here's the control's code for your reference:

=========================
[DefaultProperty("Text"),
ToolboxData("<{0}:MultiListControl
runat=server> said:
public class MultiListControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private string text;

private DropDownList lstTop;
private DropDownList lstMid;
private DropDownList lstBot;





protected bool MidVisible
{
get{
if(ViewState["MID_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["MID_VISIBLE"];
}

set{
TrackViewState();
ViewState["MID_VISIBLE"] = value;
}
}

protected bool BotVisible
{
get
{
if(ViewState["BOT_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["BOT_VISIBLE"];
}

set
{
TrackViewState();
ViewState["BOT_VISIBLE"] = value;
}
}


[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


protected override void CreateChildControls()
{
Controls.Clear();

Controls.Add(
new LiteralControl(
@"
<table width='100%'>
<tr><td>
"));

lstTop = new DropDownList();
lstTop.ID = "lstTop";

lstTop.Items.Add("----------");
lstTop.Items.Add("Top_Item_1");
lstTop.Items.Add("Top_Item_2");
lstTop.Items.Add("Top_Item_3");
lstTop.Items.Add("Top_Item_4");

Controls.Add(lstTop);

Controls.Add(
new LiteralControl(
@"<br/>"
));

lstMid = new DropDownList();
lstMid.ID = "lstMid";

Controls.Add(lstMid);

Controls.Add(
new LiteralControl(
@"<br/>"
));


lstBot = new DropDownList();
lstBot.ID = "lstBot";

Controls.Add(lstBot);


Controls.Add(
new LiteralControl(
@"
</td></tr>
</table>
"
));



lstTop.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstMid.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstBot.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);

lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack = true;


}


protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);

lstMid.Visible = MidVisible;
lstBot.Visible = BotVisible;
}




private void lst_SelectedIndexChanged(object sender, System.EventArgs e)
{

DropDownList lst = sender as DropDownList;

switch(lst.ID)
{
case "lstTop":

if(lst.SelectedIndex != 0)
{
lstMid.DataSource = GetSubItems(lst.SelectedValue);
lstMid.DataTextField = "Text";
lstMid.DataValueField= "Value";
lstMid.DataBind();

MidVisible = true;
}
else
{
MidVisible = BotVisible = false;
}

break;
case "lstMid":

lstBot.DataSource = GetSubItems(lst.SelectedValue);
lstBot.DataTextField = "Text";
lstBot.DataValueField= "Value";
lstBot.DataBind();

MidVisible = BotVisible = true;

break;
case "lstBot":



break;
}

Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
lst.EnableViewState);
}

#region --Helper functions---

public ListItemCollection GetSubItems(string parent)
{
ListItemCollection items = new ListItemCollection();
int count = parent.Length;

for(int i=0;i<count;++i)
{
items.Add(parent + "_Item_" + i);
}

return items;
}


#endregion
}

========================
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Tue, 2 Aug 2005 18:32:23 -0500
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
server
and fill
my
going
to if
so,
 
T

TS

Well Steve, I am almost done. My control works well, except its not in the
framework i just mentioned. Adding my control dynamically to the datalist's
item may be the root of the cause. i've made sure all custom controls
implmenet INamingContainer & I think all controls have their id's set, so
what else can i do?

thanks a bunch

TS said:
I have figured the cause of the problem, sort of. My main control was being
loaded dynamically during a custom data list control's ItemDataBound event,
and then added to the e.item.controls collection. Once I removed it from
here, the correct event was called in my control. the problem is i need to
keep it where it is because of the way the page works.

I tried to add INamingContainer to the custom Datalist, but that didn't
help. Any ideas what could make this happen?

thanks so much, i know i'm being a pain, but i'm stuck!

This is the custom DataLists' event:
protected override void OnItemDataBound(DataListItemEventArgs e)

{

base.OnItemDataBound(e);

Parameter parameter = (Parameter)e.Item.DataItem;

try

{

Control control;

if(parameter.Type == ParameterType.Control)

control = this.Page.LoadControl(parameter.ControlPath);

else

{

Assembly assembly = parameter.Assembly;

if(assembly == null)

{

// The control didn't declare its own assembly, so use the report's
ControlsAssembly

assembly = this.ControlsAssembly;

// Ther report's ControlsAssembly is null, so use current page's assembly

if(assembly == null)

assembly = this.Page.GetType().BaseType.Assembly;

}


control = (Control) assembly.CreateInstance(parameter.ControlTypeName);

}

control.ID = parameter.Name;

// Set up all the properties of this control from the parameter.properties

foreach(DictionaryEntry de in parameter.Properties)

SetProperty(de.Key.ToString(), de.Value.ToString(), control);


e.Item.Controls.Add(control);

}

catch (Exception ex)

{

throw new ApplicationException("Unable to render criteria. Reason: " +
ex.Message, ex);

}

}

TS said:
In testing, i removed the main parent dropdown and only left the 2 below it.
this time, the same scenario happened...when the child dropdown list
autopostsback, it's immediate parent's selectedindexchanged event fires!
I
'm
starting to pull my hair out now...I"m stuck!

please help superman

TS said:
Another problem:

while i'm waiting on your remark to my last post, i removed the sub
composite controls from my composite control so that there is only
drop
down
lists on it. During CreateChildcontrols, i load the main drop down using
databind. When the page is sent to browser for the first time, i have my
main drop down filled. I then select an item and its SelectedIndexChanged
fires and populates the send drop down list. Then when i select an
item
from
it, it posts back, and the event that gets called is the main(first)
dropdown list's SelectedIndexChanged event, which then re-populates the
second drop down list, then the control returns to the browser (The
SelectedIndexChanged event never fired for the 2nd dropdown's changed
event.???

thanks again

using System;

using System.Collections.Specialized;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text;

using OperationsTeams.Business;

using OperationsTeams.Data;

using OperationsTeams.Reporting;

using OperationsTeams.Reporting.WebControls;

namespace OperationsTeams.Web.ReportControls

{

/// <summary>

/// Summary description for FiscalAgentHierarchy.

/// </summary>

public class FiscalAgentHierarchy : WebControl, IReportParameterControl,
INamingContainer

{

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

protected override void OnLoad(EventArgs e)

{

base.OnLoad (e);


// The last state of controls from viewstate is now loaded (Before the
client data is processed)

}


protected override void OnPreRender(EventArgs e)

{

base.OnPreRender (e);

// The controls now have the client values from the the last postback

// ddlFundingSource.Visible = FundingSourceVisible;

// ddlProviders.Visible = ProviderVisible;

// ddlSites.Visible = SiteVisible;

// ddlClasses.Visible = ClassVisible;

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));

// ddlSites.Visible = true;

}

private void rysReportingYearSelector_ReportingYearChanged(object sender,
EventArgs e)

{

// this.LoadFundingSource();

// this.LoadProviders();

}

private void fasFiscalAgent_FiscalAgentChanged(object sender,
EventArgs
EventArgs
this.Controls.Add(WebHelper.MakeLiteral( said:
this.Controls.Add(ddlClasses);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

// end containing table

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

ddlFundingSource.SelectedIndexChanged += new
EventHandler(ddlFundingSource_SelectedIndexChanged);

ddlProviders.SelectedIndexChanged += new
EventHandler(ddlProviders_SelectedIndexChanged);

ddlSites.SelectedIndexChanged += new
EventHandler(ddlSites_SelectedIndexChanged);

ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
ddlSites.AutoPostBack = true;


}

private void LoadFundingSource()

{

int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;


if(fiscalAgentId != int.MinValue)

{

FundingSourceVisible = 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

{

FundingSourceVisible = false;

}

}

private void LoadProviders()

{

int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;

if(fiscalAgentId != int.MinValue)

{

// ddlSites.Items.Add(new ListItem("help","1"));

// ddlSites.Items.Add(new ListItem("me","2"));



ProviderVisible = true;

// are these dates correct???????????????????????????

ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId, new
DateTime(2005,7,1), new
DateTime(2006,6,30));//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();

ProviderVisible = false;

}

// LoadSites();

}

private void LoadSites()

{

if(ddlProviders.SelectedValue != string.Empty)

{

// Load the Site search parameters.

SiteFindArgs siteFindArgs=new SiteFindArgs();

siteFindArgs.FiscalAgentId=1;
//Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

SiteVisible = 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();

SiteVisible = false;

}

// LoadClasses();

}

private void LoadClasses()

{

if(ddlSites.SelectedValue != string.Empty)

{

AdultEdClassFindArgs adultEdClassFindArgs = new AdultEdClassFindArgs();

// adultEdClassFindArgs.FiscalAgentId =
Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);

// adultEdClassFindArgs.ReportingYearStartDate =
rysReportingYearSelector.ReportingYearStartDate;

// adultEdClassFindArgs.ReportingYearEndDate =
rysReportingYearSelector.ReportingYearEndDate;

// adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;

// adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;


ClassVisible = true;

ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);

ddlClasses.DataTextField = "Name";

ddlClasses.DataValueField = "ClassId";

ddlClasses.DataBind();

ddlClasses.Items.Insert(0, new ListItem(string.Empty, string.Empty));

}

else

{

ddlClasses.Items.Clear();

ClassVisible = 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

protected bool FundingSourceVisible

{

get

{

if(ViewState["FundingSourceVisible"] == null)

{

return false;

}

return (bool)ViewState["FundingSourceVisible"];

}

set

{

TrackViewState();

ViewState["FundingSourceVisible"] = value;

}

}

protected bool ProviderVisible

{

get

{

if(ViewState["ProviderVisible"] == null)

{

return false;

}

return (bool)ViewState["ProviderVisible"];

}

set

{

TrackViewState();

ViewState["ProviderVisible"] = value;

}

}

protected bool SiteVisible

{

get

{

if(ViewState["SiteVisible"] == null)

{

return false;

}

return (bool)ViewState["SiteVisible"];

}

set

{

TrackViewState();

ViewState["SiteVisible"] = value;

}

}

protected bool ClassVisible

{

get

{

if(ViewState["ClassVisible"] == null)

{

return false;

}

return (bool)ViewState["ClassVisible"];

}

set

{

TrackViewState();

ViewState["ClassVisible"] = value;

}

}

#endregion

#region Private Member Variables

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

}

}


Hi TS,

See you again :), seems you're rushing in a asp.net project these days?
For the question you mentioned in this post, here are some of my
understanding and suggestions:

1. ASP.NET controls derived from Control will automatically maintain its
ViewStates according to the asp.net web page's events sequence. So for
composite control, those nested sub Controls' status (properties
which
be
persistd in Viewsstate ) will be store and retrieve automatically.

2. However, there're some thing we need to care when building composite
control:
#remember to implement INamingContainer for controls which will have
nested
sub controls. Otherwise, even handler mapping, ViewState loading will
occur
unexpectedly.

#Do remember to assign a explicit ID for each sub controls(same
reason
as
#1). Also, please always try best to add subcontrols in the
"CreateChildControls" method(just create control hierarchy) and put
manipulating code in postback event or PreRender event.

In addition, for your detaile scenario, I've just built a very
simple
demo
control which have three dropdownlists and The "Top" one will display
first(other twos invisible) and according to the top one's
selection,
the
"Mid" dropdownlist will be pouplated and the same when the "mid"'s
selection changed......

Here's the control's code for your reference:

=========================
[DefaultProperty("Text"),
ToolboxData("<{0}:MultiListControl
runat=server> said:
public class MultiListControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private string text;

private DropDownList lstTop;
private DropDownList lstMid;
private DropDownList lstBot;





protected bool MidVisible
{
get{
if(ViewState["MID_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["MID_VISIBLE"];
}

set{
TrackViewState();
ViewState["MID_VISIBLE"] = value;
}
}

protected bool BotVisible
{
get
{
if(ViewState["BOT_VISIBLE"] == null)
{
return false;
}

return (bool)ViewState["BOT_VISIBLE"];
}

set
{
TrackViewState();
ViewState["BOT_VISIBLE"] = value;
}
}


[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


protected override void CreateChildControls()
{
Controls.Clear();

Controls.Add(
new LiteralControl(
@"
<table width='100%'>
<tr><td>
"));

lstTop = new DropDownList();
lstTop.ID = "lstTop";

lstTop.Items.Add("----------");
lstTop.Items.Add("Top_Item_1");
lstTop.Items.Add("Top_Item_2");
lstTop.Items.Add("Top_Item_3");
lstTop.Items.Add("Top_Item_4");

Controls.Add(lstTop);

Controls.Add(
new LiteralControl(
@"<br/>"
));

lstMid = new DropDownList();
lstMid.ID = "lstMid";

Controls.Add(lstMid);

Controls.Add(
new LiteralControl(
@"<br/>"
));


lstBot = new DropDownList();
lstBot.ID = "lstBot";

Controls.Add(lstBot);


Controls.Add(
new LiteralControl(
@"
</td></tr>
</table>
"
));



lstTop.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstMid.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);
lstBot.SelectedIndexChanged +=new EventHandler(lst_SelectedIndexChanged);

lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack = true;


}


protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);

lstMid.Visible = MidVisible;
lstBot.Visible = BotVisible;
}




private void lst_SelectedIndexChanged(object sender,
System.EventArgs
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
So
now filled
and going
 
S

Steven Cheng[MSFT]

Hi TS,

First, I'm glad that you've got your composite control work, all the
dropdownlist's postback events can fire correctly,yes?

As for the new problem you encountered when adding your composite control
into DataList's item, is the DataList the asp.net's buildin DataList
control? And since you mentioned that you dynamically add your control
into it, how do you dynamically add your custom control? Will there occur
problem if you statically add your control into DataList?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Wed, 3 Aug 2005 19:07:16 -0500
| Lines: 1153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well Steve, I am almost done. My control works well, except its not in the
| framework i just mentioned. Adding my control dynamically to the
datalist's
| item may be the root of the cause. i've made sure all custom controls
| implmenet INamingContainer & I think all controls have their id's set, so
| what else can i do?
|
| thanks a bunch
|
| | > I have figured the cause of the problem, sort of. My main control was
| being
| > loaded dynamically during a custom data list control's ItemDataBound
| event,
| > and then added to the e.item.controls collection. Once I removed it from
| > here, the correct event was called in my control. the problem is i need
to
| > keep it where it is because of the way the page works.
| >
| > I tried to add INamingContainer to the custom Datalist, but that didn't
| > help. Any ideas what could make this happen?
| >
| > thanks so much, i know i'm being a pain, but i'm stuck!
| >
| > This is the custom DataLists' event:
| > protected override void OnItemDataBound(DataListItemEventArgs e)
| >
| > {
| >
| > base.OnItemDataBound(e);
| >
| > Parameter parameter = (Parameter)e.Item.DataItem;
| >
| > try
| >
| > {
| >
| > Control control;
| >
| > if(parameter.Type == ParameterType.Control)
| >
| > control = this.Page.LoadControl(parameter.ControlPath);
| >
| > else
| >
| > {
| >
| > Assembly assembly = parameter.Assembly;
| >
| > if(assembly == null)
| >
| > {
| >
| > // The control didn't declare its own assembly, so use the report's
| > ControlsAssembly
| >
| > assembly = this.ControlsAssembly;
| >
| > // Ther report's ControlsAssembly is null, so use current page's
assembly
| >
| > if(assembly == null)
| >
| > assembly = this.Page.GetType().BaseType.Assembly;
| >
| > }
| >
| >
| > control = (Control) assembly.CreateInstance(parameter.ControlTypeName);
| >
| > }
| >
| > control.ID = parameter.Name;
| >
| > // Set up all the properties of this control from the
parameter.properties
| >
| > foreach(DictionaryEntry de in parameter.Properties)
| >
| > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| >
| >
| > e.Item.Controls.Add(control);
| >
| > }
| >
| > catch (Exception ex)
| >
| > {
| >
| > throw new ApplicationException("Unable to render criteria. Reason: " +
| > ex.Message, ex);
| >
| > }
| >
| > }
| >
| > | > > In testing, i removed the main parent dropdown and only left the 2
below
| > it.
| > > this time, the same scenario happened...when the child dropdown list
| > > autopostsback, it's immediate parent's selectedindexchanged event
fires!
| I
| > 'm
| > > starting to pull my hair out now...I"m stuck!
| > >
| > > please help superman
| > >
| > > | > > > Another problem:
| > > >
| > > > while i'm waiting on your remark to my last post, i removed the sub
| > > > composite controls from my composite control so that there is only
| drop
| > > down
| > > > lists on it. During CreateChildcontrols, i load the main drop down
| using
| > > > databind. When the page is sent to browser for the first time, i
have
| my
| > > > main drop down filled. I then select an item and its
| > SelectedIndexChanged
| > > > fires and populates the send drop down list. Then when i select an
| item
| > > from
| > > > it, it posts back, and the event that gets called is the main(first)
| > > > dropdown list's SelectedIndexChanged event, which then re-populates
| the
| > > > second drop down list, then the control returns to the browser (The
| > > > SelectedIndexChanged event never fired for the 2nd dropdown's
changed
| > > > event.???
| > > >
| > > > thanks again
| > > >
| > > > using System;
| > > >
| > > > using System.Collections.Specialized;
| > > >
| > > > using System.Web.UI;
| > > >
| > > > using System.Web.UI.WebControls;
| > > >
| > > > using System.Text;
| > > >
| > > > using OperationsTeams.Business;
| > > >
| > > > using OperationsTeams.Data;
| > > >
| > > > using OperationsTeams.Reporting;
| > > >
| > > > using OperationsTeams.Reporting.WebControls;
| > > >
| > > > namespace OperationsTeams.Web.ReportControls
| > > >
| > > > {
| > > >
| > > > /// <summary>
| > > >
| > > > /// Summary description for FiscalAgentHierarchy.
| > > >
| > > > /// </summary>
| > > >
| > > > public class FiscalAgentHierarchy : WebControl,
| IReportParameterControl,
| > > > INamingContainer
| > > >
| > > > {
| > > >
| > > > 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
| > > >
| > > > protected override void OnLoad(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnLoad (e);
| > > >
| > > >
| > > > // The last state of controls from viewstate is now loaded (Before
the
| > > > client data is processed)
| > > >
| > > > }
| > > >
| > > >
| > > > protected override void OnPreRender(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnPreRender (e);
| > > >
| > > > // The controls now have the client values from the the last
postback
| > > >
| > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > > >
| > > > // ddlProviders.Visible = ProviderVisible;
| > > >
| > > > // ddlSites.Visible = SiteVisible;
| > > >
| > > > // ddlClasses.Visible = ClassVisible;
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > > // ddlSites.Visible = true;
| > > >
| > > > }
| > > >
| > > > 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 ddlFundingSource_SelectedIndexChanged(object sender,
| > > EventArgs
| > > > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlProviders_SelectedIndexChanged(object sender,
| EventArgs
| > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlSites_SelectedIndexChanged(object sender, EventArgs
e)
| > > >
| > > > {
| > > >
| > > > LoadClasses();
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > protected override void CreateChildControls()
| > > >
| > > > {
| > > >
| > > > this.ddlFundingSource = new DropDownList();
| > > >
| > > > this.ddlProviders = new DropDownList();
| > > >
| > > > this.ddlSites = new DropDownList();
| > > >
| > > > this.ddlClasses = new DropDownList();
| > > >
| > > > ddlFundingSource.ID = FundingSourceControlId;
| > > >
| > > > ddlProviders.ID = ProvidersControlId;
| > > >
| > > > ddlSites.ID = SitesControlId;
| > > >
| > > > ddlClasses.ID = ClassesControlId;
| > > >
| > > >
| > > > LoadProviders();
| > > >
| > > > // 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>"));
| > > >
| > > > ddlFundingSource.SelectedIndexChanged += new
| > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > > >
| > > > ddlProviders.SelectedIndexChanged += new
| > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > > >
| > > > ddlSites.SelectedIndexChanged += new
| > > > EventHandler(ddlSites_SelectedIndexChanged);
| > > >
| > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > > > ddlSites.AutoPostBack = true;
| > > >
| > > >
| > > > }
| > > >
| > > > private void LoadFundingSource()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = 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
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = false;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > private void LoadProviders()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > >
| > > >
| > > > ProviderVisible = true;
| > > >
| > > > // are these dates correct???????????????????????????
| > > >
| > > > ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
new
| > > > DateTime(2005,7,1), new
| > > >
| DateTime(2006,6,30));//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();
| > > >
| > > > ProviderVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadSites();
| > > >
| > > > }
| > > >
| > > > private void LoadSites()
| > > >
| > > > {
| > > >
| > > > if(ddlProviders.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > // Load the Site search parameters.
| > > >
| > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > > >
| > > > siteFindArgs.FiscalAgentId=1;
| > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > SiteVisible = 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();
| > > >
| > > > SiteVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadClasses();
| > > >
| > > > }
| > > >
| > > > private void LoadClasses()
| > > >
| > > > {
| > > >
| > > > if(ddlSites.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| AdultEdClassFindArgs();
| > > >
| > > > // adultEdClassFindArgs.FiscalAgentId =
| > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > > > rysReportingYearSelector.ReportingYearStartDate;
| > > >
| > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > > > rysReportingYearSelector.ReportingYearEndDate;
| > > >
| > > > // adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;
| > > >
| > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > > >
| > > >
| > > > ClassVisible = true;
| > > >
| > > > ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);
| > > >
| > > > ddlClasses.DataTextField = "Name";
| > > >
| > > > ddlClasses.DataValueField = "ClassId";
| > > >
| > > > ddlClasses.DataBind();
| > > >
| > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
string.Empty));
| > > >
| > > > }
| > > >
| > > > else
| > > >
| > > > {
| > > >
| > > > ddlClasses.Items.Clear();
| > > >
| > > > ClassVisible = 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
| > > >
| > > > protected bool FundingSourceVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["FundingSourceVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["FundingSourceVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["FundingSourceVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ProviderVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ProviderVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ProviderVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ProviderVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool SiteVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["SiteVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["SiteVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["SiteVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ClassVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ClassVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ClassVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ClassVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > #region Private Member Variables
| > > >
| > > > 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
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > >
| > > > | > > > > Hi TS,
| > > > >
| > > > > See you again :), seems you're rushing in a asp.net project these
| > days?
| > > > > For the question you mentioned in this post, here are some of my
| > > > > understanding and suggestions:
| > > > >
| > > > > 1. ASP.NET controls derived from Control will automatically
maintain
| > its
| > > > > ViewStates according to the asp.net web page's events sequence. So
| for
| > > > > composite control, those nested sub Controls' status (properties
| which
| > > be
| > > > > persistd in Viewsstate ) will be store and retrieve automatically.
| > > > >
| > > > > 2. However, there're some thing we need to care when building
| > composite
| > > > > control:
| > > > > #remember to implement INamingContainer for controls which will
have
| > > > nested
| > > > > sub controls. Otherwise, even handler mapping, ViewState loading
| will
| > > > occur
| > > > > unexpectedly.
| > > > >
| > > > > #Do remember to assign a explicit ID for each sub controls(same
| reason
| > > as
| > > > > #1). Also, please always try best to add subcontrols in the
| > > > > "CreateChildControls" method(just create control hierarchy) and
put
| > > > > manipulating code in postback event or PreRender event.
| > > > >
| > > > > In addition, for your detaile scenario, I've just built a very
| simple
| > > demo
| > > > > control which have three dropdownlists and The "Top" one will
| display
| > > > > first(other twos invisible) and according to the top one's
| selection,
| > > the
| > > > > "Mid" dropdownlist will be pouplated and the same when the "mid"'s
| > > > > selection changed......
| > > > >
| > > > > Here's the control's code for your reference:
| > > > >
| > > > > =========================
| > > > > [DefaultProperty("Text"),
| > > > > ToolboxData("<{0}:MultiListControl
| > > runat=server></{0}:MultiListControl>")]
| > > > > public class MultiListControl :
| System.Web.UI.WebControls.WebControl,
| > > > > INamingContainer
| > > > > {
| > > > > private string text;
| > > > >
| > > > > private DropDownList lstTop;
| > > > > private DropDownList lstMid;
| > > > > private DropDownList lstBot;
| > > > >
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > protected bool MidVisible
| > > > > {
| > > > > get{
| > > > > if(ViewState["MID_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["MID_VISIBLE"];
| > > > > }
| > > > >
| > > > > set{
| > > > > TrackViewState();
| > > > > ViewState["MID_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > > protected bool BotVisible
| > > > > {
| > > > > get
| > > > > {
| > > > > if(ViewState["BOT_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["BOT_VISIBLE"];
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > TrackViewState();
| > > > > ViewState["BOT_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > [Bindable(true),
| > > > > Category("Appearance"),
| > > > > DefaultValue("")]
| > > > > public string Text
| > > > > {
| > > > > get
| > > > > {
| > > > > return text;
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > text = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > protected override void CreateChildControls()
| > > > > {
| > > > > Controls.Clear();
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > <table width='100%'>
| > > > > <tr><td>
| > > > > "));
| > > > >
| > > > > lstTop = new DropDownList();
| > > > > lstTop.ID = "lstTop";
| > > > >
| > > > > lstTop.Items.Add("----------");
| > > > > lstTop.Items.Add("Top_Item_1");
| > > > > lstTop.Items.Add("Top_Item_2");
| > > > > lstTop.Items.Add("Top_Item_3");
| > > > > lstTop.Items.Add("Top_Item_4");
| > > > >
| > > > > Controls.Add(lstTop);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > > lstMid = new DropDownList();
| > > > > lstMid.ID = "lstMid";
| > > > >
| > > > > Controls.Add(lstMid);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > >
| > > > > lstBot = new DropDownList();
| > > > > lstBot.ID = "lstBot";
| > > > >
| > > > > Controls.Add(lstBot);
| > > > >
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > </td></tr>
| > > > > </table>
| > > > > "
| > > > > ));
| > > > >
| > > > >
| > > > >
| > > > > lstTop.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstMid.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstBot.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > >
| > > > > lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack =
| > true;
| > > > >
| > > > >
| > > > > }
| > > > >
| > > > >
| > > > > protected override void OnPreRender(EventArgs e)
| > > > > {
| > > > > base.OnPreRender (e);
| > > > >
| > > > > lstMid.Visible = MidVisible;
| > > > > lstBot.Visible = BotVisible;
| > > > > }
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > private void lst_SelectedIndexChanged(object sender,
| System.EventArgs
| > e)
| > > > > {
| > > > >
| > > > > DropDownList lst = sender as DropDownList;
| > > > >
| > > > > switch(lst.ID)
| > > > > {
| > > > > case "lstTop":
| > > > >
| > > > > if(lst.SelectedIndex != 0)
| > > > > {
| > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstMid.DataTextField = "Text";
| > > > > lstMid.DataValueField= "Value";
| > > > > lstMid.DataBind();
| > > > >
| > > > > MidVisible = true;
| > > > > }
| > > > > else
| > > > > {
| > > > > MidVisible = BotVisible = false;
| > > > > }
| > > > >
| > > > > break;
| > > > > case "lstMid":
| > > > >
| > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstBot.DataTextField = "Text";
| > > > > lstBot.DataValueField= "Value";
| > > > > lstBot.DataBind();
| > > > >
| > > > > MidVisible = BotVisible = true;
| > > > >
| > > > > break;
| > > > > case "lstBot":
| > > > >
| > > > >
| > > > >
| > > > > break;
| > > > > }
| > > > >
| > > > > Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
| > > > > lst.EnableViewState);
| > > > > }
| > > > >
| > > > > #region --Helper functions---
| > > > >
| > > > > public ListItemCollection GetSubItems(string parent)
| > > > > {
| > > > > ListItemCollection items = new ListItemCollection();
| > > > > int count = parent.Length;
| > > > >
| > > > > for(int i=0;i<count;++i)
| > > > > {
| > > > > items.Add(parent + "_Item_" + i);
| > > > > }
| > > > >
| > > > > return items;
| > > > > }
| > > > >
| > > > >
| > > > > #endregion
| > > > > }
| > > > >
| > > > > ========================
| > > > > Hope helps. Thanks,
| > > > >
| > > > > Steven Cheng
| > > > > Microsoft Online Support
| > > > >
| > > > > Get Secure! www.microsoft.com/security
| > > > > (This posting is provided "AS IS", with no warranties, and confers
| no
| > > > > rights.)
| > > > >
| > > > >
| > > > > --------------------
| > > > > | From: "TS" <[email protected]>
| > > > > | References: <[email protected]>
| > > > > | Subject: Re: explanation of when need to repopulate control
| > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > > > > | Lines: 39
| > > > > | X-Priority: 3
| > > > > | X-MSMail-Priority: Normal
| > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > > > > | Message-ID: <[email protected]>
| > > > > | Newsgroups:
| > > > >
| > > >
| > >
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > > > > framework.aspnet.buildingcontrols
| > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > > > > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > > > > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > > > > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > > > > |
| > > > > | sorry, heres the scenario i'm trying to accomplish:
| > > > > | I have a composite control that contains 4 drop down lists. When
| the
| > > > page
| > > > > | loads initially, i want the first drop down filled and the rest
| > > > invisible.
| > > > > | When you select an item in this ddl, it posts back to the server
| and
| > > > based
| > > > > | on its value, it populates its immediate child's drop down list.
| So
| > > now
| > > > > the
| > > > > | top ddl has a value selected and the 2nd one just has its items
| > > > populated.
| > > > > | Then when the 2nd drop down list gets selected, it posts to the
| > server
| > > > and
| > > > > | its value is used to populate(filter) the items for the 3rd drop
| > down
| > > > > | list...and so on for each drop down list.
| > > > > |
| > > > > | Please tell me what i need to do to handle post back data and
| > maintain
| > > > > state
| > > > > | from one postback to another while keeping the drop downlists
| filled
| > > and
| > > > > | their values persisted.
| > > > > |
| > > > > | thank you again!
| > > > > |
| > > > > |
| > > > > | | > > > > | > I have a quesiton:
| > > > > | > if i have a composite control and on its intial page loading,
i
| > fill
| > > > my
| > > > > | (sub
| > > > > | > control) drop down list's items collection from the database
and
| > > > return.
| > > > > | > When the user hits a button to cause postback, the control is
| > going
| > > to
| > > > > get
| > > > > | > initialized, then does its items collection that i filled on
the
| > > > initial
| > > > > | > page request get repopulated from viewstate? And on top of
that,
| > if
| > > > so,
| > > > > | does
| > > > > | > the list item that person selected in the drop down list again
| set
| > > > > itself
| > > > > | as
| > > > > | > the selected item in the list?
| > > > > | >
| > > > > | > OR do i have to re-load the items on every page request and
then
| > > > > populate
| > > > > | > its value some other way???
| > > > > | >
| > > > > | > thanks a bunch
| > > > > | >
| > > > > | >
| > > > > |
| > > > > |
| > > > > |
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|
 
T

TS

First the control works great, the main cause was it being in the datalist.

The Datalist is a custom control that inherits from DataList, and overrides
some stuff, but its basically a DataList. If you look thru this post, you'll
see the code i attached during the onItemDataBind method when i add the
control dynamically to e.Item (Get assembly then CreateInstance of class and
add it in). I need to have the flexibility to dynamically add it because
what gets loaded is determined from an xml document, so i dont' know ahead
of time which control gets instantiated.

It seems that when a postback event occurs, the control whose event handler
should get run isn't, its a different control's event handler, usually the
control that is above it in the control hierarchy. It seems the event
handlers aren't getting wired up correctly.

Any ideas on this conflict

Thanks again

Steven Cheng said:
Hi TS,

First, I'm glad that you've got your composite control work, all the
dropdownlist's postback events can fire correctly,yes?

As for the new problem you encountered when adding your composite control
into DataList's item, is the DataList the asp.net's buildin DataList
control? And since you mentioned that you dynamically add your control
into it, how do you dynamically add your custom control? Will there occur
problem if you statically add your control into DataList?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Wed, 3 Aug 2005 19:07:16 -0500
| Lines: 1153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well Steve, I am almost done. My control works well, except its not in the
| framework i just mentioned. Adding my control dynamically to the
datalist's
| item may be the root of the cause. i've made sure all custom controls
| implmenet INamingContainer & I think all controls have their id's set, so
| what else can i do?
|
| thanks a bunch
|
| | > I have figured the cause of the problem, sort of. My main control was
| being
| > loaded dynamically during a custom data list control's ItemDataBound
| event,
| > and then added to the e.item.controls collection. Once I removed it from
| > here, the correct event was called in my control. the problem is i need
to
| > keep it where it is because of the way the page works.
| >
| > I tried to add INamingContainer to the custom Datalist, but that didn't
| > help. Any ideas what could make this happen?
| >
| > thanks so much, i know i'm being a pain, but i'm stuck!
| >
| > This is the custom DataLists' event:
| > protected override void OnItemDataBound(DataListItemEventArgs e)
| >
| > {
| >
| > base.OnItemDataBound(e);
| >
| > Parameter parameter = (Parameter)e.Item.DataItem;
| >
| > try
| >
| > {
| >
| > Control control;
| >
| > if(parameter.Type == ParameterType.Control)
| >
| > control = this.Page.LoadControl(parameter.ControlPath);
| >
| > else
| >
| > {
| >
| > Assembly assembly = parameter.Assembly;
| >
| > if(assembly == null)
| >
| > {
| >
| > // The control didn't declare its own assembly, so use the report's
| > ControlsAssembly
| >
| > assembly = this.ControlsAssembly;
| >
| > // Ther report's ControlsAssembly is null, so use current page's
assembly
| >
| > if(assembly == null)
| >
| > assembly = this.Page.GetType().BaseType.Assembly;
| >
| > }
| >
| >
| > control = (Control) assembly.CreateInstance(parameter.ControlTypeName);
| >
| > }
| >
| > control.ID = parameter.Name;
| >
| > // Set up all the properties of this control from the
parameter.properties
| >
| > foreach(DictionaryEntry de in parameter.Properties)
| >
| > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| >
| >
| > e.Item.Controls.Add(control);
| >
| > }
| >
| > catch (Exception ex)
| >
| > {
| >
| > throw new ApplicationException("Unable to render criteria. Reason: " +
| > ex.Message, ex);
| >
| > }
| >
| > }
| >
| > | > > In testing, i removed the main parent dropdown and only left the 2
below
| > it.
| > > this time, the same scenario happened...when the child dropdown list
| > > autopostsback, it's immediate parent's selectedindexchanged event
fires!
| I
| > 'm
| > > starting to pull my hair out now...I"m stuck!
| > >
| > > please help superman
| > >
| > > | > > > Another problem:
| > > >
| > > > while i'm waiting on your remark to my last post, i removed the sub
| > > > composite controls from my composite control so that there is only
| drop
| > > down
| > > > lists on it. During CreateChildcontrols, i load the main drop down
| using
| > > > databind. When the page is sent to browser for the first time, i
have
| my
| > > > main drop down filled. I then select an item and its
| > SelectedIndexChanged
| > > > fires and populates the send drop down list. Then when i select an
| item
| > > from
| > > > it, it posts back, and the event that gets called is the main(first)
| > > > dropdown list's SelectedIndexChanged event, which then re-populates
| the
| > > > second drop down list, then the control returns to the browser (The
| > > > SelectedIndexChanged event never fired for the 2nd dropdown's
changed
| > > > event.???
| > > >
| > > > thanks again
| > > >
| > > > using System;
| > > >
| > > > using System.Collections.Specialized;
| > > >
| > > > using System.Web.UI;
| > > >
| > > > using System.Web.UI.WebControls;
| > > >
| > > > using System.Text;
| > > >
| > > > using OperationsTeams.Business;
| > > >
| > > > using OperationsTeams.Data;
| > > >
| > > > using OperationsTeams.Reporting;
| > > >
| > > > using OperationsTeams.Reporting.WebControls;
| > > >
| > > > namespace OperationsTeams.Web.ReportControls
| > > >
| > > > {
| > > >
| > > > /// <summary>
| > > >
| > > > /// Summary description for FiscalAgentHierarchy.
| > > >
| > > > /// </summary>
| > > >
| > > > public class FiscalAgentHierarchy : WebControl,
| IReportParameterControl,
| > > > INamingContainer
| > > >
| > > > {
| > > >
| > > > 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
| > > >
| > > > protected override void OnLoad(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnLoad (e);
| > > >
| > > >
| > > > // The last state of controls from viewstate is now loaded (Before
the
| > > > client data is processed)
| > > >
| > > > }
| > > >
| > > >
| > > > protected override void OnPreRender(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnPreRender (e);
| > > >
| > > > // The controls now have the client values from the the last
postback
| > > >
| > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > > >
| > > > // ddlProviders.Visible = ProviderVisible;
| > > >
| > > > // ddlSites.Visible = SiteVisible;
| > > >
| > > > // ddlClasses.Visible = ClassVisible;
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > > // ddlSites.Visible = true;
| > > >
| > > > }
| > > >
| > > > 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 ddlFundingSource_SelectedIndexChanged(object sender,
| > > EventArgs
| > > > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlProviders_SelectedIndexChanged(object sender,
| EventArgs
| > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlSites_SelectedIndexChanged(object sender, EventArgs
e)
| > > >
| > > > {
| > > >
| > > > LoadClasses();
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > protected override void CreateChildControls()
| > > >
| > > > {
| > > >
| > > > this.ddlFundingSource = new DropDownList();
| > > >
| > > > this.ddlProviders = new DropDownList();
| > > >
| > > > this.ddlSites = new DropDownList();
| > > >
| > > > this.ddlClasses = new DropDownList();
| > > >
| > > > ddlFundingSource.ID = FundingSourceControlId;
| > > >
| > > > ddlProviders.ID = ProvidersControlId;
| > > >
| > > > ddlSites.ID = SitesControlId;
| > > >
| > > > ddlClasses.ID = ClassesControlId;
| > > >
| > > >
| > > > LoadProviders();
| > > >
| > > > // 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( said:
| > > > );
| > > >
| > > > 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( said:
| > > >
| > > > this.Controls.Add(ddlClasses);
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > // end containing table
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > ddlFundingSource.SelectedIndexChanged += new
| > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > > >
| > > > ddlProviders.SelectedIndexChanged += new
| > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > > >
| > > > ddlSites.SelectedIndexChanged += new
| > > > EventHandler(ddlSites_SelectedIndexChanged);
| > > >
| > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > > > ddlSites.AutoPostBack = true;
| > > >
| > > >
| > > > }
| > > >
| > > > private void LoadFundingSource()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = 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
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = false;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > private void LoadProviders()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > >
| > > >
| > > > ProviderVisible = true;
| > > >
| > > > // are these dates correct???????????????????????????
| > > >
| > > > ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
new
| > > > DateTime(2005,7,1), new
| > > >
| DateTime(2006,6,30));//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();
| > > >
| > > > ProviderVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadSites();
| > > >
| > > > }
| > > >
| > > > private void LoadSites()
| > > >
| > > > {
| > > >
| > > > if(ddlProviders.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > // Load the Site search parameters.
| > > >
| > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > > >
| > > > siteFindArgs.FiscalAgentId=1;
| > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > SiteVisible = 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();
| > > >
| > > > SiteVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadClasses();
| > > >
| > > > }
| > > >
| > > > private void LoadClasses()
| > > >
| > > > {
| > > >
| > > > if(ddlSites.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| AdultEdClassFindArgs();
| > > >
| > > > // adultEdClassFindArgs.FiscalAgentId =
| > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > > > rysReportingYearSelector.ReportingYearStartDate;
| > > >
| > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > > > rysReportingYearSelector.ReportingYearEndDate;
| > > >
| > > > // adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;
| > > >
| > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > > >
| > > >
| > > > ClassVisible = true;
| > > >
| > > > ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);
| > > >
| > > > ddlClasses.DataTextField = "Name";
| > > >
| > > > ddlClasses.DataValueField = "ClassId";
| > > >
| > > > ddlClasses.DataBind();
| > > >
| > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
string.Empty));
| > > >
| > > > }
| > > >
| > > > else
| > > >
| > > > {
| > > >
| > > > ddlClasses.Items.Clear();
| > > >
| > > > ClassVisible = 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
| > > >
| > > > protected bool FundingSourceVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["FundingSourceVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["FundingSourceVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["FundingSourceVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ProviderVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ProviderVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ProviderVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ProviderVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool SiteVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["SiteVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["SiteVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["SiteVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ClassVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ClassVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ClassVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ClassVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > #region Private Member Variables
| > > >
| > > > 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
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > >
| > > > | > > > > Hi TS,
| > > > >
| > > > > See you again :), seems you're rushing in a asp.net project these
| > days?
| > > > > For the question you mentioned in this post, here are some of my
| > > > > understanding and suggestions:
| > > > >
| > > > > 1. ASP.NET controls derived from Control will automatically
maintain
| > its
| > > > > ViewStates according to the asp.net web page's events sequence. So
| for
| > > > > composite control, those nested sub Controls' status (properties
| which
| > > be
| > > > > persistd in Viewsstate ) will be store and retrieve automatically.
| > > > >
| > > > > 2. However, there're some thing we need to care when building
| > composite
| > > > > control:
| > > > > #remember to implement INamingContainer for controls which will
have
| > > > nested
| > > > > sub controls. Otherwise, even handler mapping, ViewState loading
| will
| > > > occur
| > > > > unexpectedly.
| > > > >
| > > > > #Do remember to assign a explicit ID for each sub controls(same
| reason
| > > as
| > > > > #1). Also, please always try best to add subcontrols in the
| > > > > "CreateChildControls" method(just create control hierarchy) and
put
| > > > > manipulating code in postback event or PreRender event.
| > > > >
| > > > > In addition, for your detaile scenario, I've just built a very
| simple
| > > demo
| > > > > control which have three dropdownlists and The "Top" one will
| display
| > > > > first(other twos invisible) and according to the top one's
| selection,
| > > the
| > > > > "Mid" dropdownlist will be pouplated and the same when the "mid"'s
| > > > > selection changed......
| > > > >
| > > > > Here's the control's code for your reference:
| > > > >
| > > > > =========================
| > > > > [DefaultProperty("Text"),
| > > > > ToolboxData("<{0}:MultiListControl
| > > runat=server></{0}:MultiListControl>")]
| > > > > public class MultiListControl :
| System.Web.UI.WebControls.WebControl,
| > > > > INamingContainer
| > > > > {
| > > > > private string text;
| > > > >
| > > > > private DropDownList lstTop;
| > > > > private DropDownList lstMid;
| > > > > private DropDownList lstBot;
| > > > >
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > protected bool MidVisible
| > > > > {
| > > > > get{
| > > > > if(ViewState["MID_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["MID_VISIBLE"];
| > > > > }
| > > > >
| > > > > set{
| > > > > TrackViewState();
| > > > > ViewState["MID_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > > protected bool BotVisible
| > > > > {
| > > > > get
| > > > > {
| > > > > if(ViewState["BOT_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["BOT_VISIBLE"];
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > TrackViewState();
| > > > > ViewState["BOT_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > [Bindable(true),
| > > > > Category("Appearance"),
| > > > > DefaultValue("")]
| > > > > public string Text
| > > > > {
| > > > > get
| > > > > {
| > > > > return text;
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > text = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > protected override void CreateChildControls()
| > > > > {
| > > > > Controls.Clear();
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > <table width='100%'>
| > > > > <tr><td>
| > > > > "));
| > > > >
| > > > > lstTop = new DropDownList();
| > > > > lstTop.ID = "lstTop";
| > > > >
| > > > > lstTop.Items.Add("----------");
| > > > > lstTop.Items.Add("Top_Item_1");
| > > > > lstTop.Items.Add("Top_Item_2");
| > > > > lstTop.Items.Add("Top_Item_3");
| > > > > lstTop.Items.Add("Top_Item_4");
| > > > >
| > > > > Controls.Add(lstTop);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > > lstMid = new DropDownList();
| > > > > lstMid.ID = "lstMid";
| > > > >
| > > > > Controls.Add(lstMid);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > >
| > > > > lstBot = new DropDownList();
| > > > > lstBot.ID = "lstBot";
| > > > >
| > > > > Controls.Add(lstBot);
| > > > >
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > </td></tr>
| > > > > </table>
| > > > > "
| > > > > ));
| > > > >
| > > > >
| > > > >
| > > > > lstTop.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstMid.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstBot.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > >
| > > > > lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack =
| > true;
| > > > >
| > > > >
| > > > > }
| > > > >
| > > > >
| > > > > protected override void OnPreRender(EventArgs e)
| > > > > {
| > > > > base.OnPreRender (e);
| > > > >
| > > > > lstMid.Visible = MidVisible;
| > > > > lstBot.Visible = BotVisible;
| > > > > }
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > private void lst_SelectedIndexChanged(object sender,
| System.EventArgs
| > e)
| > > > > {
| > > > >
| > > > > DropDownList lst = sender as DropDownList;
| > > > >
| > > > > switch(lst.ID)
| > > > > {
| > > > > case "lstTop":
| > > > >
| > > > > if(lst.SelectedIndex != 0)
| > > > > {
| > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstMid.DataTextField = "Text";
| > > > > lstMid.DataValueField= "Value";
| > > > > lstMid.DataBind();
| > > > >
| > > > > MidVisible = true;
| > > > > }
| > > > > else
| > > > > {
| > > > > MidVisible = BotVisible = false;
| > > > > }
| > > > >
| > > > > break;
| > > > > case "lstMid":
| > > > >
| > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstBot.DataTextField = "Text";
| > > > > lstBot.DataValueField= "Value";
| > > > > lstBot.DataBind();
| > > > >
| > > > > MidVisible = BotVisible = true;
| > > > >
| > > > > break;
| > > > > case "lstBot":
| > > > >
| > > > >
| > > > >
| > > > > break;
| > > > > }
| > > > >
| > > > > Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
| > > > > lst.EnableViewState);
| > > > > }
| > > > >
| > > > > #region --Helper functions---
| > > > >
| > > > > public ListItemCollection GetSubItems(string parent)
| > > > > {
| > > > > ListItemCollection items = new ListItemCollection();
| > > > > int count = parent.Length;
| > > > >
| > > > > for(int i=0;i<count;++i)
| > > > > {
| > > > > items.Add(parent + "_Item_" + i);
| > > > > }
| > > > >
| > > > > return items;
| > > > > }
| > > > >
| > > > >
| > > > > #endregion
| > > > > }
| > > > >
| > > > > ========================
| > > > > Hope helps. Thanks,
| > > > >
| > > > > Steven Cheng
| > > > > Microsoft Online Support
| > > > >
| > > > > Get Secure! www.microsoft.com/security
| > > > > (This posting is provided "AS IS", with no warranties, and confers
| no
| > > > > rights.)
| > > > >
| > > > >
| > > > > --------------------
| > > > > | From: "TS" <[email protected]>
| > > > > | References: <[email protected]>
| > > > > | Subject: Re: explanation of when need to repopulate control
| > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > > > > | Lines: 39
| > > > > | X-Priority: 3
| > > > > | X-MSMail-Priority: Normal
| > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > > > > | Message-ID: <[email protected]>
| > > > > | Newsgroups:
| > > > >
| > > >
| > >
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > > > > framework.aspnet.buildingcontrols
| > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > > > > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > > > > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > > > > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > > > > |
| > > > > | sorry, heres the scenario i'm trying to accomplish:
| > > > > | I have a composite control that contains 4 drop down lists. When
| the
| > > > page
| > > > > | loads initially, i want the first drop down filled and the rest
| > > > invisible.
| > > > > | When you select an item in this ddl, it posts back to the server
| and
| > > > based
| > > > > | on its value, it populates its immediate child's drop down list.
| So
| > > now
| > > > > the
| > > > > | top ddl has a value selected and the 2nd one just has its items
| > > > populated.
| > > > > | Then when the 2nd drop down list gets selected, it posts to the
| > server
| > > > and
| > > > > | its value is used to populate(filter) the items for the 3rd drop
| > down
| > > > > | list...and so on for each drop down list.
| > > > > |
| > > > > | Please tell me what i need to do to handle post back data and
| > maintain
| > > > > state
| > > > > | from one postback to another while keeping the drop downlists
| filled
| > > and
| > > > > | their values persisted.
| > > > > |
| > > > > | thank you again!
| > > > > |
| > > > > |
| > > > > | | > > > > | > I have a quesiton:
| > > > > | > if i have a composite control and on its intial page loading,
i
| > fill
| > > > my
| > > > > | (sub
| > > > > | > control) drop down list's items collection from the database
and
| > > > return.
| > > > > | > When the user hits a button to cause postback, the control is
| > going
| > > to
| > > > > get
| > > > > | > initialized, then does its items collection that i filled on
the
| > > > initial
| > > > > | > page request get repopulated from viewstate? And on top of
that,
| > if
| > > > so,
| > > > > | does
| > > > > | > the list item that person selected in the drop down list again
| set
| > > > > itself
| > > > > | as
| > > > > | > the selected item in the list?
| > > > > | >
| > > > > | > OR do i have to re-load the items on every page request and
then
| > > > > populate
| > > > > | > its value some other way???
| > > > > | >
| > > > > | > thanks a bunch
| > > > > | >
| > > > > | >
| > > > > |
| > > > > |
| > > > > |
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|
 
T

TS

I have double checked that all web controls have an id and all custom
controls have iNamingContainer interface. What else do i need???

is there anybody else at work that may have an idea?

thanks

Steven Cheng said:
Hi TS,

First, I'm glad that you've got your composite control work, all the
dropdownlist's postback events can fire correctly,yes?

As for the new problem you encountered when adding your composite control
into DataList's item, is the DataList the asp.net's buildin DataList
control? And since you mentioned that you dynamically add your control
into it, how do you dynamically add your custom control? Will there occur
problem if you statically add your control into DataList?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Wed, 3 Aug 2005 19:07:16 -0500
| Lines: 1153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well Steve, I am almost done. My control works well, except its not in the
| framework i just mentioned. Adding my control dynamically to the
datalist's
| item may be the root of the cause. i've made sure all custom controls
| implmenet INamingContainer & I think all controls have their id's set, so
| what else can i do?
|
| thanks a bunch
|
| | > I have figured the cause of the problem, sort of. My main control was
| being
| > loaded dynamically during a custom data list control's ItemDataBound
| event,
| > and then added to the e.item.controls collection. Once I removed it from
| > here, the correct event was called in my control. the problem is i need
to
| > keep it where it is because of the way the page works.
| >
| > I tried to add INamingContainer to the custom Datalist, but that didn't
| > help. Any ideas what could make this happen?
| >
| > thanks so much, i know i'm being a pain, but i'm stuck!
| >
| > This is the custom DataLists' event:
| > protected override void OnItemDataBound(DataListItemEventArgs e)
| >
| > {
| >
| > base.OnItemDataBound(e);
| >
| > Parameter parameter = (Parameter)e.Item.DataItem;
| >
| > try
| >
| > {
| >
| > Control control;
| >
| > if(parameter.Type == ParameterType.Control)
| >
| > control = this.Page.LoadControl(parameter.ControlPath);
| >
| > else
| >
| > {
| >
| > Assembly assembly = parameter.Assembly;
| >
| > if(assembly == null)
| >
| > {
| >
| > // The control didn't declare its own assembly, so use the report's
| > ControlsAssembly
| >
| > assembly = this.ControlsAssembly;
| >
| > // Ther report's ControlsAssembly is null, so use current page's
assembly
| >
| > if(assembly == null)
| >
| > assembly = this.Page.GetType().BaseType.Assembly;
| >
| > }
| >
| >
| > control = (Control) assembly.CreateInstance(parameter.ControlTypeName);
| >
| > }
| >
| > control.ID = parameter.Name;
| >
| > // Set up all the properties of this control from the
parameter.properties
| >
| > foreach(DictionaryEntry de in parameter.Properties)
| >
| > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| >
| >
| > e.Item.Controls.Add(control);
| >
| > }
| >
| > catch (Exception ex)
| >
| > {
| >
| > throw new ApplicationException("Unable to render criteria. Reason: " +
| > ex.Message, ex);
| >
| > }
| >
| > }
| >
| > | > > In testing, i removed the main parent dropdown and only left the 2
below
| > it.
| > > this time, the same scenario happened...when the child dropdown list
| > > autopostsback, it's immediate parent's selectedindexchanged event
fires!
| I
| > 'm
| > > starting to pull my hair out now...I"m stuck!
| > >
| > > please help superman
| > >
| > > | > > > Another problem:
| > > >
| > > > while i'm waiting on your remark to my last post, i removed the sub
| > > > composite controls from my composite control so that there is only
| drop
| > > down
| > > > lists on it. During CreateChildcontrols, i load the main drop down
| using
| > > > databind. When the page is sent to browser for the first time, i
have
| my
| > > > main drop down filled. I then select an item and its
| > SelectedIndexChanged
| > > > fires and populates the send drop down list. Then when i select an
| item
| > > from
| > > > it, it posts back, and the event that gets called is the main(first)
| > > > dropdown list's SelectedIndexChanged event, which then re-populates
| the
| > > > second drop down list, then the control returns to the browser (The
| > > > SelectedIndexChanged event never fired for the 2nd dropdown's
changed
| > > > event.???
| > > >
| > > > thanks again
| > > >
| > > > using System;
| > > >
| > > > using System.Collections.Specialized;
| > > >
| > > > using System.Web.UI;
| > > >
| > > > using System.Web.UI.WebControls;
| > > >
| > > > using System.Text;
| > > >
| > > > using OperationsTeams.Business;
| > > >
| > > > using OperationsTeams.Data;
| > > >
| > > > using OperationsTeams.Reporting;
| > > >
| > > > using OperationsTeams.Reporting.WebControls;
| > > >
| > > > namespace OperationsTeams.Web.ReportControls
| > > >
| > > > {
| > > >
| > > > /// <summary>
| > > >
| > > > /// Summary description for FiscalAgentHierarchy.
| > > >
| > > > /// </summary>
| > > >
| > > > public class FiscalAgentHierarchy : WebControl,
| IReportParameterControl,
| > > > INamingContainer
| > > >
| > > > {
| > > >
| > > > 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
| > > >
| > > > protected override void OnLoad(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnLoad (e);
| > > >
| > > >
| > > > // The last state of controls from viewstate is now loaded (Before
the
| > > > client data is processed)
| > > >
| > > > }
| > > >
| > > >
| > > > protected override void OnPreRender(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnPreRender (e);
| > > >
| > > > // The controls now have the client values from the the last
postback
| > > >
| > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > > >
| > > > // ddlProviders.Visible = ProviderVisible;
| > > >
| > > > // ddlSites.Visible = SiteVisible;
| > > >
| > > > // ddlClasses.Visible = ClassVisible;
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > > // ddlSites.Visible = true;
| > > >
| > > > }
| > > >
| > > > 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 ddlFundingSource_SelectedIndexChanged(object sender,
| > > EventArgs
| > > > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlProviders_SelectedIndexChanged(object sender,
| EventArgs
| > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlSites_SelectedIndexChanged(object sender, EventArgs
e)
| > > >
| > > > {
| > > >
| > > > LoadClasses();
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > protected override void CreateChildControls()
| > > >
| > > > {
| > > >
| > > > this.ddlFundingSource = new DropDownList();
| > > >
| > > > this.ddlProviders = new DropDownList();
| > > >
| > > > this.ddlSites = new DropDownList();
| > > >
| > > > this.ddlClasses = new DropDownList();
| > > >
| > > > ddlFundingSource.ID = FundingSourceControlId;
| > > >
| > > > ddlProviders.ID = ProvidersControlId;
| > > >
| > > > ddlSites.ID = SitesControlId;
| > > >
| > > > ddlClasses.ID = ClassesControlId;
| > > >
| > > >
| > > > LoadProviders();
| > > >
| > > > // 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( said:
| > > > );
| > > >
| > > > 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( said:
| > > >
| > > > this.Controls.Add(ddlClasses);
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > // end containing table
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > ddlFundingSource.SelectedIndexChanged += new
| > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > > >
| > > > ddlProviders.SelectedIndexChanged += new
| > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > > >
| > > > ddlSites.SelectedIndexChanged += new
| > > > EventHandler(ddlSites_SelectedIndexChanged);
| > > >
| > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > > > ddlSites.AutoPostBack = true;
| > > >
| > > >
| > > > }
| > > >
| > > > private void LoadFundingSource()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = 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
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = false;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > private void LoadProviders()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > >
| > > >
| > > > ProviderVisible = true;
| > > >
| > > > // are these dates correct???????????????????????????
| > > >
| > > > ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
new
| > > > DateTime(2005,7,1), new
| > > >
| DateTime(2006,6,30));//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();
| > > >
| > > > ProviderVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadSites();
| > > >
| > > > }
| > > >
| > > > private void LoadSites()
| > > >
| > > > {
| > > >
| > > > if(ddlProviders.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > // Load the Site search parameters.
| > > >
| > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > > >
| > > > siteFindArgs.FiscalAgentId=1;
| > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > SiteVisible = 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();
| > > >
| > > > SiteVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadClasses();
| > > >
| > > > }
| > > >
| > > > private void LoadClasses()
| > > >
| > > > {
| > > >
| > > > if(ddlSites.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| AdultEdClassFindArgs();
| > > >
| > > > // adultEdClassFindArgs.FiscalAgentId =
| > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > > > rysReportingYearSelector.ReportingYearStartDate;
| > > >
| > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > > > rysReportingYearSelector.ReportingYearEndDate;
| > > >
| > > > // adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;
| > > >
| > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > > >
| > > >
| > > > ClassVisible = true;
| > > >
| > > > ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);
| > > >
| > > > ddlClasses.DataTextField = "Name";
| > > >
| > > > ddlClasses.DataValueField = "ClassId";
| > > >
| > > > ddlClasses.DataBind();
| > > >
| > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
string.Empty));
| > > >
| > > > }
| > > >
| > > > else
| > > >
| > > > {
| > > >
| > > > ddlClasses.Items.Clear();
| > > >
| > > > ClassVisible = 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
| > > >
| > > > protected bool FundingSourceVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["FundingSourceVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["FundingSourceVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["FundingSourceVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ProviderVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ProviderVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ProviderVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ProviderVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool SiteVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["SiteVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["SiteVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["SiteVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ClassVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ClassVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ClassVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ClassVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > #region Private Member Variables
| > > >
| > > > 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
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > >
| > > > | > > > > Hi TS,
| > > > >
| > > > > See you again :), seems you're rushing in a asp.net project these
| > days?
| > > > > For the question you mentioned in this post, here are some of my
| > > > > understanding and suggestions:
| > > > >
| > > > > 1. ASP.NET controls derived from Control will automatically
maintain
| > its
| > > > > ViewStates according to the asp.net web page's events sequence. So
| for
| > > > > composite control, those nested sub Controls' status (properties
| which
| > > be
| > > > > persistd in Viewsstate ) will be store and retrieve automatically.
| > > > >
| > > > > 2. However, there're some thing we need to care when building
| > composite
| > > > > control:
| > > > > #remember to implement INamingContainer for controls which will
have
| > > > nested
| > > > > sub controls. Otherwise, even handler mapping, ViewState loading
| will
| > > > occur
| > > > > unexpectedly.
| > > > >
| > > > > #Do remember to assign a explicit ID for each sub controls(same
| reason
| > > as
| > > > > #1). Also, please always try best to add subcontrols in the
| > > > > "CreateChildControls" method(just create control hierarchy) and
put
| > > > > manipulating code in postback event or PreRender event.
| > > > >
| > > > > In addition, for your detaile scenario, I've just built a very
| simple
| > > demo
| > > > > control which have three dropdownlists and The "Top" one will
| display
| > > > > first(other twos invisible) and according to the top one's
| selection,
| > > the
| > > > > "Mid" dropdownlist will be pouplated and the same when the "mid"'s
| > > > > selection changed......
| > > > >
| > > > > Here's the control's code for your reference:
| > > > >
| > > > > =========================
| > > > > [DefaultProperty("Text"),
| > > > > ToolboxData("<{0}:MultiListControl
| > > runat=server></{0}:MultiListControl>")]
| > > > > public class MultiListControl :
| System.Web.UI.WebControls.WebControl,
| > > > > INamingContainer
| > > > > {
| > > > > private string text;
| > > > >
| > > > > private DropDownList lstTop;
| > > > > private DropDownList lstMid;
| > > > > private DropDownList lstBot;
| > > > >
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > protected bool MidVisible
| > > > > {
| > > > > get{
| > > > > if(ViewState["MID_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["MID_VISIBLE"];
| > > > > }
| > > > >
| > > > > set{
| > > > > TrackViewState();
| > > > > ViewState["MID_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > > protected bool BotVisible
| > > > > {
| > > > > get
| > > > > {
| > > > > if(ViewState["BOT_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["BOT_VISIBLE"];
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > TrackViewState();
| > > > > ViewState["BOT_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > [Bindable(true),
| > > > > Category("Appearance"),
| > > > > DefaultValue("")]
| > > > > public string Text
| > > > > {
| > > > > get
| > > > > {
| > > > > return text;
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > text = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > protected override void CreateChildControls()
| > > > > {
| > > > > Controls.Clear();
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > <table width='100%'>
| > > > > <tr><td>
| > > > > "));
| > > > >
| > > > > lstTop = new DropDownList();
| > > > > lstTop.ID = "lstTop";
| > > > >
| > > > > lstTop.Items.Add("----------");
| > > > > lstTop.Items.Add("Top_Item_1");
| > > > > lstTop.Items.Add("Top_Item_2");
| > > > > lstTop.Items.Add("Top_Item_3");
| > > > > lstTop.Items.Add("Top_Item_4");
| > > > >
| > > > > Controls.Add(lstTop);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > > lstMid = new DropDownList();
| > > > > lstMid.ID = "lstMid";
| > > > >
| > > > > Controls.Add(lstMid);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > >
| > > > > lstBot = new DropDownList();
| > > > > lstBot.ID = "lstBot";
| > > > >
| > > > > Controls.Add(lstBot);
| > > > >
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > </td></tr>
| > > > > </table>
| > > > > "
| > > > > ));
| > > > >
| > > > >
| > > > >
| > > > > lstTop.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstMid.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstBot.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > >
| > > > > lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack =
| > true;
| > > > >
| > > > >
| > > > > }
| > > > >
| > > > >
| > > > > protected override void OnPreRender(EventArgs e)
| > > > > {
| > > > > base.OnPreRender (e);
| > > > >
| > > > > lstMid.Visible = MidVisible;
| > > > > lstBot.Visible = BotVisible;
| > > > > }
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > private void lst_SelectedIndexChanged(object sender,
| System.EventArgs
| > e)
| > > > > {
| > > > >
| > > > > DropDownList lst = sender as DropDownList;
| > > > >
| > > > > switch(lst.ID)
| > > > > {
| > > > > case "lstTop":
| > > > >
| > > > > if(lst.SelectedIndex != 0)
| > > > > {
| > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstMid.DataTextField = "Text";
| > > > > lstMid.DataValueField= "Value";
| > > > > lstMid.DataBind();
| > > > >
| > > > > MidVisible = true;
| > > > > }
| > > > > else
| > > > > {
| > > > > MidVisible = BotVisible = false;
| > > > > }
| > > > >
| > > > > break;
| > > > > case "lstMid":
| > > > >
| > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstBot.DataTextField = "Text";
| > > > > lstBot.DataValueField= "Value";
| > > > > lstBot.DataBind();
| > > > >
| > > > > MidVisible = BotVisible = true;
| > > > >
| > > > > break;
| > > > > case "lstBot":
| > > > >
| > > > >
| > > > >
| > > > > break;
| > > > > }
| > > > >
| > > > > Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
| > > > > lst.EnableViewState);
| > > > > }
| > > > >
| > > > > #region --Helper functions---
| > > > >
| > > > > public ListItemCollection GetSubItems(string parent)
| > > > > {
| > > > > ListItemCollection items = new ListItemCollection();
| > > > > int count = parent.Length;
| > > > >
| > > > > for(int i=0;i<count;++i)
| > > > > {
| > > > > items.Add(parent + "_Item_" + i);
| > > > > }
| > > > >
| > > > > return items;
| > > > > }
| > > > >
| > > > >
| > > > > #endregion
| > > > > }
| > > > >
| > > > > ========================
| > > > > Hope helps. Thanks,
| > > > >
| > > > > Steven Cheng
| > > > > Microsoft Online Support
| > > > >
| > > > > Get Secure! www.microsoft.com/security
| > > > > (This posting is provided "AS IS", with no warranties, and confers
| no
| > > > > rights.)
| > > > >
| > > > >
| > > > > --------------------
| > > > > | From: "TS" <[email protected]>
| > > > > | References: <[email protected]>
| > > > > | Subject: Re: explanation of when need to repopulate control
| > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > > > > | Lines: 39
| > > > > | X-Priority: 3
| > > > > | X-MSMail-Priority: Normal
| > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > > > > | Message-ID: <[email protected]>
| > > > > | Newsgroups:
| > > > >
| > > >
| > >
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > > > > framework.aspnet.buildingcontrols
| > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > > > > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > > > > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > > > > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > > > > |
| > > > > | sorry, heres the scenario i'm trying to accomplish:
| > > > > | I have a composite control that contains 4 drop down lists. When
| the
| > > > page
| > > > > | loads initially, i want the first drop down filled and the rest
| > > > invisible.
| > > > > | When you select an item in this ddl, it posts back to the server
| and
| > > > based
| > > > > | on its value, it populates its immediate child's drop down list.
| So
| > > now
| > > > > the
| > > > > | top ddl has a value selected and the 2nd one just has its items
| > > > populated.
| > > > > | Then when the 2nd drop down list gets selected, it posts to the
| > server
| > > > and
| > > > > | its value is used to populate(filter) the items for the 3rd drop
| > down
| > > > > | list...and so on for each drop down list.
| > > > > |
| > > > > | Please tell me what i need to do to handle post back data and
| > maintain
| > > > > state
| > > > > | from one postback to another while keeping the drop downlists
| filled
| > > and
| > > > > | their values persisted.
| > > > > |
| > > > > | thank you again!
| > > > > |
| > > > > |
| > > > > | | > > > > | > I have a quesiton:
| > > > > | > if i have a composite control and on its intial page loading,
i
| > fill
| > > > my
| > > > > | (sub
| > > > > | > control) drop down list's items collection from the database
and
| > > > return.
| > > > > | > When the user hits a button to cause postback, the control is
| > going
| > > to
| > > > > get
| > > > > | > initialized, then does its items collection that i filled on
the
| > > > initial
| > > > > | > page request get repopulated from viewstate? And on top of
that,
| > if
| > > > so,
| > > > > | does
| > > > > | > the list item that person selected in the drop down list again
| set
| > > > > itself
| > > > > | as
| > > > > | > the selected item in the list?
| > > > > | >
| > > > > | > OR do i have to re-load the items on every page request and
then
| > > > > populate
| > > > > | > its value some other way???
| > > > > | >
| > > > > | > thanks a bunch
| > > > > | >
| > > > > | >
| > > > > |
| > > > > |
| > > > > |
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|
 
T

TS

this might help to see the control's ids. What i have is the same composite
control - one declared on the page statically and then one that is nested
inside the custom DataList control. The actual class name is:
FiscalAgentHierarchy. It is statically declared in the page as faHierARchy,
and dynamically as @FiscalAgentHierarchy inside DataList (rplCriteria).

Hope this helps


Control Tree
Control Id Type Render Size Bytes (including children) Viewstate Size
Bytes (excluding children)
__PAGE ASP.ReportSelection_aspx 61307 20
_ctl4 System.Web.UI.ResourceBasedLiteralControl 566 0
Form1 System.Web.UI.HtmlControls.HtmlForm 60720 0
_ctl2 TEA.ControlledLibrary.AgencyWide.Web.UI.Header 1355 0
_ctl2:_ctl6 System.Web.UI.LiteralControl 59 0
_ctl2:_ctl7 System.Web.UI.LiteralControl 29 0
_ctl2:_ctl0 System.Web.UI.WebControls.Image 89 0
_ctl2:_ctl8 System.Web.UI.LiteralControl 34 0
_ctl2:_ctl1 System.Web.UI.WebControls.HyperLink 81 0
_ctl2:_ctl9 System.Web.UI.LiteralControl 14 0
_ctl2:_ctl2 System.Web.UI.WebControls.HyperLink 121 0
_ctl2:_ctl10 System.Web.UI.LiteralControl 14 0
_ctl2:_ctl3 System.Web.UI.WebControls.HyperLink 104 0
_ctl2:_ctl11 System.Web.UI.LiteralControl 14 0
_ctl2:_ctl4 System.Web.UI.WebControls.HyperLink 102 0
_ctl2:_ctl12 System.Web.UI.LiteralControl 10 0
_ctl2:_ctl13 System.Web.UI.LiteralControl 61 0
_ctl2:_ctl5
TEA.ControlledLibrary.AgencyWide.Web.UI.ApplicationHeader 623 0
_ctl2:_ctl5:_ctl0 System.Web.UI.LiteralControl 83 0
_ctl2:_ctl5:_ctl1 System.Web.UI.LiteralControl 44 0
_ctl2:_ctl5:_ctl2 System.Web.UI.LiteralControl 55 0
_ctl2:_ctl5:_ctl3 System.Web.UI.LiteralControl 48 0
_ctl2:_ctl5:_ctl4 System.Web.UI.LiteralControl 61 0
_ctl2:_ctl5:_ctl5 System.Web.UI.LiteralControl 40 0
_ctl2:_ctl5:_ctl6 System.Web.UI.LiteralControl 74 0
_ctl2:_ctl5:_ctl7 System.Web.UI.LiteralControl 38 0
_ctl2:_ctl5:_ctl8 System.Web.UI.LiteralControl 41 0
_ctl2:_ctl5:_ctl9 System.Web.UI.LiteralControl 13 0
_ctl2:_ctl5:_ctl10 System.Web.UI.LiteralControl 66 0
_ctl5 System.Web.UI.LiteralControl 59 0
_ctl0 TEA.ControlledLibrary.AgencyWide.Web.UI.Navigation.Menu
9710 6896
_ctl0:_ctl9 System.Web.UI.LiteralControl 43 0
_ctl0:_ctl0 System.Web.UI.HtmlControls.HtmlGenericControl
164 0
_ctl0:_ctl1 System.Web.UI.HtmlControls.HtmlGenericControl
184 0
_ctl0:_ctl2 System.Web.UI.WebControls.Table 1047 0
_ctl0:_ctl10 System.Web.UI.WebControls.TableRow 875 0
_ctl0:_ctl11 System.Web.UI.WebControls.TableCell
860 0
_ctl0:_ctl3 System.Web.UI.WebControls.Table 733 0
_ctl0:_ctl12 System.Web.UI.WebControls.TableRow 581 0
_ctl0:_ctl13 System.Web.UI.WebControls.TableCell
566 0
_ctl0:_ctl4 System.Web.UI.WebControls.Image 73
0
_ctl0:_ctl5 System.Web.UI.WebControls.Literal
12 0
_ctl0:_ctl6 System.Web.UI.WebControls.Table 7534 0
_ctl0:_ctl14 System.Web.UI.WebControls.TableRow 552 0
_ctl0:_ctl15 System.Web.UI.WebControls.TableCell
537 0
_ctl0:_ctl16 System.Web.UI.WebControls.TableRow 627 0
_ctl0:_ctl17 System.Web.UI.WebControls.TableCell
613 0
_ctl0:_ctl7 System.Web.UI.WebControls.Image 70
0
_ctl0:_ctl8 System.Web.UI.WebControls.Literal
7 0
_ctl0:_ctl18 System.Web.UI.WebControls.TableRow 562 0
_ctl0:_ctl19 System.Web.UI.WebControls.TableCell
548 0
_ctl0:_ctl20 System.Web.UI.WebControls.TableRow 588 0
_ctl0:_ctl21 System.Web.UI.WebControls.TableCell
574 0
_ctl0:_ctl22 System.Web.UI.WebControls.TableRow 587 0
_ctl0:_ctl23 System.Web.UI.WebControls.TableCell
573 0
_ctl0:_ctl24 System.Web.UI.WebControls.TableRow 545 0
_ctl0:_ctl25 System.Web.UI.WebControls.TableCell
531 0
_ctl0:_ctl26 System.Web.UI.WebControls.TableRow 558 0
_ctl0:_ctl27 System.Web.UI.WebControls.TableCell
544 0
_ctl0:_ctl28 System.Web.UI.WebControls.TableRow 586 0
_ctl0:_ctl29 System.Web.UI.WebControls.TableCell
572 0
_ctl0:_ctl30 System.Web.UI.WebControls.TableRow 560 0
_ctl0:_ctl31 System.Web.UI.WebControls.TableCell
546 0
_ctl0:_ctl32 System.Web.UI.WebControls.TableRow 577 0
_ctl0:_ctl33 System.Web.UI.WebControls.TableCell
563 0
_ctl0:_ctl34 System.Web.UI.WebControls.TableRow 577 0
_ctl0:_ctl35 System.Web.UI.WebControls.TableCell
563 0
_ctl0:_ctl36 System.Web.UI.WebControls.TableRow 545 0
_ctl0:_ctl37 System.Web.UI.WebControls.TableCell
531 0
_ctl0:_ctl38 System.Web.UI.WebControls.TableRow 542 0
_ctl0:_ctl39 System.Web.UI.WebControls.TableCell
528 0
_ctl0:_ctl40 System.Web.UI.LiteralControl 5 0
_ctl6 System.Web.UI.LiteralControl 81 0
_ctl7 System.Web.UI.LiteralControl 26 0
_ctl8 System.Web.UI.LiteralControl 55 0
_ctl9 System.Web.UI.LiteralControl 8 0
_ctl1
TEA.ControlledLibrary.AgencyWide.Web.UI.Navigation.NavPath 16 0
_ctl10 System.Web.UI.LiteralControl 10 0
_ctl11 System.Web.UI.LiteralControl 8 0
_ctl12 System.Web.UI.LiteralControl 41 0
lblReportTitle System.Web.UI.WebControls.Label 98 40
_ctl13 System.Web.UI.LiteralControl 52 0
pnlBeginCriteria TEA.Teams.Web.Controls.ExpandingPanelBegin
517 0
pnlBeginCriteria:_ctl0 System.Web.UI.LiteralControl 482 0
_ctl14 System.Web.UI.LiteralControl 8 0
faHierARchy TEA.Teams.Web.ReportControls.FiscalAgentHierarchy
10195 0
faHierARchy:_ctl0 System.Web.UI.WebControls.Literal 21 0
faHierARchy:_ctl1 System.Web.UI.WebControls.Literal 20 0
faHierARchy:1 System.Web.UI.WebControls.Label 46 0
faHierARchy:_ctl2 System.Web.UI.WebControls.Literal 9 0
faHierARchy:rysReportingYearSelector
TEA.Teams.Web.ReportControls.ReportingYearReportSelector 1092 0
faHierARchy:rysReportingYearSelector:_ctl0
System.Web.UI.WebControls.Literal 7 0
faHierARchy:rysReportingYearSelector:_ctl1
System.Web.UI.WebControls.Literal 8 0
faHierARchy:rysReportingYearSelector:ddlSchoolYear
System.Web.UI.WebControls.DropDownList 636 308
faHierARchy:rysReportingYearSelector:_ctl2
System.Web.UI.WebControls.Literal 9 0

faHierARchy:rysReportingYearSelector:ddlReportYearGroup
System.Web.UI.WebControls.DropDownList 414 236
faHierARchy:rysReportingYearSelector:_ctl3
System.Web.UI.WebControls.Literal 5 0
faHierARchy:rysReportingYearSelector:_ctl4
System.Web.UI.WebControls.Literal 13 0
faHierARchy:_ctl3 System.Web.UI.WebControls.Literal 10 0
faHierARchy:_ctl4 System.Web.UI.WebControls.Literal 20 0
faHierARchy:2 System.Web.UI.WebControls.Label 44 0
faHierARchy:_ctl5 System.Web.UI.WebControls.Literal 9 0
faHierARchy:fasFiscalAgentSelector
TEA.Teams.Web.ReportControls.FiscalAgentReportSelector 8728 0
faHierARchy:fasFiscalAgentSelector:_ctl0
System.Web.UI.WebControls.Literal 22 0
faHierARchy:fasFiscalAgentSelector:ddlFiscalAgentId
System.Web.UI.WebControls.DropDownList 3582 60
faHierARchy:fasFiscalAgentSelector:lblFiscalAgentId
System.Web.UI.WebControls.Label 0 0
faHierARchy:fasFiscalAgentSelector:_ctl1
System.Web.UI.WebControls.Literal 9 0
faHierARchy:fasFiscalAgentSelector:ddlFiscalAgentName
System.Web.UI.WebControls.DropDownList 5097 52
faHierARchy:fasFiscalAgentSelector:lblFiscalAgentName
System.Web.UI.WebControls.Label 0 0
faHierARchy:fasFiscalAgentSelector:_ctl2
System.Web.UI.WebControls.Literal 18 0
faHierARchy:_ctl6 System.Web.UI.WebControls.Literal 10 0
faHierARchy:_ctl7 System.Web.UI.WebControls.Literal 20 0
faHierARchy:3 System.Web.UI.WebControls.Label 0 36
faHierARchy:_ctl8 System.Web.UI.WebControls.Literal 9 0
faHierARchy:ddlFundingSource
System.Web.UI.WebControls.DropDownList 0 44
faHierARchy:_ctl9 System.Web.UI.WebControls.Literal 10 0
faHierARchy:_ctl10 System.Web.UI.WebControls.Literal 20 0
faHierARchy:4 System.Web.UI.WebControls.Label 0 36
faHierARchy:_ctl11 System.Web.UI.WebControls.Literal 9 0
faHierARchy:ddlProviders
System.Web.UI.WebControls.DropDownList 0 44
faHierARchy:_ctl12 System.Web.UI.WebControls.Literal 10 0
faHierARchy:_ctl13 System.Web.UI.WebControls.Literal 20 0
faHierARchy:5 System.Web.UI.WebControls.Label 0 36
faHierARchy:_ctl14 System.Web.UI.WebControls.Literal 9 0
faHierARchy:ddlSites
System.Web.UI.WebControls.DropDownList 0 44
faHierARchy:_ctl15 System.Web.UI.WebControls.Literal 10 0
faHierARchy:_ctl16 System.Web.UI.WebControls.Literal 20 0
faHierARchy:6 System.Web.UI.WebControls.Label 0 36
faHierARchy:_ctl17 System.Web.UI.WebControls.Literal 9 0
faHierARchy:ddlClasses
System.Web.UI.WebControls.DropDownList 0 44
faHierARchy:_ctl18 System.Web.UI.WebControls.Literal 10 0
_ctl15 System.Web.UI.LiteralControl 35 0
rplCriteria
TEA.Teams.Reporting.WebControls.ReportParameterList 11278 3152
rplCriteria:_ctl0 System.Web.UI.WebControls.DataListItem
11139 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy
TEA.Teams.Web.ReportControls.FiscalAgentHierarchy 11139 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl0
System.Web.UI.WebControls.Literal 21 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl1
System.Web.UI.WebControls.Literal 20 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:1
System.Web.UI.WebControls.Label 74 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl2
System.Web.UI.WebControls.Literal 9 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector
TEA.Teams.Web.ReportControls.ReportingYearReportSelector 1288 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector:_ctl0
System.Web.UI.WebControls.Literal 7 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector:_ctl1
System.Web.UI.WebControls.Literal 8 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector:ddlSchoolYe
ar System.Web.UI.WebControls.DropDownList 740 308

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector:_ctl2
System.Web.UI.WebControls.Literal 9 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector:ddlReportYe
arGroup System.Web.UI.WebControls.DropDownList 506 236

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector:_ctl3
System.Web.UI.WebControls.Literal 5 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:rysReportingYearSelector:_ctl4
System.Web.UI.WebControls.Literal 13 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl3
System.Web.UI.WebControls.Literal 10 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl4
System.Web.UI.WebControls.Literal 20 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:2
System.Web.UI.WebControls.Label 72 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl5
System.Web.UI.WebControls.Literal 9 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector
TEA.Teams.Web.ReportControls.FiscalAgentReportSelector 9392 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector:_ctl0
System.Web.UI.WebControls.Literal 22 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector:ddlFiscalAgen
tId System.Web.UI.WebControls.DropDownList 3914 60

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector:lblFiscalAgen
tId System.Web.UI.WebControls.Label 0 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector:_ctl1
System.Web.UI.WebControls.Literal 9 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector:ddlFiscalAgen
tName System.Web.UI.WebControls.DropDownList 5429 52

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector:lblFiscalAgen
tName System.Web.UI.WebControls.Label 0 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:fasFiscalAgentSelector:_ctl2
System.Web.UI.WebControls.Literal 18 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl6
System.Web.UI.WebControls.Literal 10 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl7
System.Web.UI.WebControls.Literal 20 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:3
System.Web.UI.WebControls.Label 0 36
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl8
System.Web.UI.WebControls.Literal 9 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:ddlFundingSource
System.Web.UI.WebControls.DropDownList 0 44
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl9
System.Web.UI.WebControls.Literal 10 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl10
System.Web.UI.WebControls.Literal 20 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:4
System.Web.UI.WebControls.Label 0 36
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl11
System.Web.UI.WebControls.Literal 9 0

rplCriteria:_ctl0:mad:FiscalAgentHierarchy:ddlProviders
System.Web.UI.WebControls.DropDownList 0 44
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl12
System.Web.UI.WebControls.Literal 10 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl13
System.Web.UI.WebControls.Literal 20 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:5
System.Web.UI.WebControls.Label 0 36
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl14
System.Web.UI.WebControls.Literal 9 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:ddlSites
System.Web.UI.WebControls.DropDownList 0 44
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl15
System.Web.UI.WebControls.Literal 10 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl16
System.Web.UI.WebControls.Literal 20 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:6
System.Web.UI.WebControls.Label 0 36
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl17
System.Web.UI.WebControls.Literal 9 0
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:ddlClasses
System.Web.UI.WebControls.DropDownList 0 44
rplCriteria:_ctl0:mad:FiscalAgentHierarchy:_ctl18
System.Web.UI.WebControls.Literal 10 0
_ctl16 System.Web.UI.LiteralControl 105 0
btnRun System.Web.UI.WebControls.Button 83 0
_ctl17 System.Web.UI.LiteralControl 100 0
pnlEndCriteria TEA.Teams.Web.Controls.ExpandingPanelEnd 18 0
pnlEndCriteria:_ctl0 System.Web.UI.LiteralControl 18 0
_ctl18 System.Web.UI.LiteralControl 52 0
_ctl19 System.Web.UI.LiteralControl 54 0
_ctl3 TEA.ControlledLibrary.AgencyWide.Web.UI.Footer 1043 0
_ctl3:_ctl4 System.Web.UI.LiteralControl 55 0
_ctl3:_ctl5 System.Web.UI.LiteralControl 43 0
_ctl3:_ctl6 System.Web.UI.LiteralControl 14 0
_ctl3:_ctl7 System.Web.UI.LiteralControl 44 0
_ctl3:_ctl8 System.Web.UI.LiteralControl 92 0
_ctl3:_ctl9 System.Web.UI.LiteralControl 48 0
_ctl3:_ctl10 System.Web.UI.LiteralControl 27 0
_ctl3:_ctl11 System.Web.UI.LiteralControl 37 0
_ctl3:_ctl0 System.Web.UI.WebControls.HyperLink 67 0
_ctl3:_ctl12 System.Web.UI.LiteralControl 14 0
_ctl3:_ctl1 System.Web.UI.WebControls.HyperLink 92 0
_ctl3:_ctl13 System.Web.UI.LiteralControl 14 0
_ctl3:_ctl2 System.Web.UI.WebControls.HyperLink 74 0
_ctl3:_ctl14 System.Web.UI.LiteralControl 14 0
_ctl3:_ctl3 System.Web.UI.WebControls.HyperLink 83 0
_ctl3:_ctl15 System.Web.UI.LiteralControl 10 0
_ctl3:_ctl16 System.Web.UI.LiteralControl 27 0
_ctl3:_ctl17 System.Web.UI.LiteralControl 249 0
_ctl20 System.Web.UI.LiteralControl 21 0


Steven Cheng said:
Hi TS,

First, I'm glad that you've got your composite control work, all the
dropdownlist's postback events can fire correctly,yes?

As for the new problem you encountered when adding your composite control
into DataList's item, is the DataList the asp.net's buildin DataList
control? And since you mentioned that you dynamically add your control
into it, how do you dynamically add your custom control? Will there occur
problem if you statically add your control into DataList?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Wed, 3 Aug 2005 19:07:16 -0500
| Lines: 1153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well Steve, I am almost done. My control works well, except its not in the
| framework i just mentioned. Adding my control dynamically to the
datalist's
| item may be the root of the cause. i've made sure all custom controls
| implmenet INamingContainer & I think all controls have their id's set, so
| what else can i do?
|
| thanks a bunch
|
| | > I have figured the cause of the problem, sort of. My main control was
| being
| > loaded dynamically during a custom data list control's ItemDataBound
| event,
| > and then added to the e.item.controls collection. Once I removed it from
| > here, the correct event was called in my control. the problem is i need
to
| > keep it where it is because of the way the page works.
| >
| > I tried to add INamingContainer to the custom Datalist, but that didn't
| > help. Any ideas what could make this happen?
| >
| > thanks so much, i know i'm being a pain, but i'm stuck!
| >
| > This is the custom DataLists' event:
| > protected override void OnItemDataBound(DataListItemEventArgs e)
| >
| > {
| >
| > base.OnItemDataBound(e);
| >
| > Parameter parameter = (Parameter)e.Item.DataItem;
| >
| > try
| >
| > {
| >
| > Control control;
| >
| > if(parameter.Type == ParameterType.Control)
| >
| > control = this.Page.LoadControl(parameter.ControlPath);
| >
| > else
| >
| > {
| >
| > Assembly assembly = parameter.Assembly;
| >
| > if(assembly == null)
| >
| > {
| >
| > // The control didn't declare its own assembly, so use the report's
| > ControlsAssembly
| >
| > assembly = this.ControlsAssembly;
| >
| > // Ther report's ControlsAssembly is null, so use current page's
assembly
| >
| > if(assembly == null)
| >
| > assembly = this.Page.GetType().BaseType.Assembly;
| >
| > }
| >
| >
| > control = (Control) assembly.CreateInstance(parameter.ControlTypeName);
| >
| > }
| >
| > control.ID = parameter.Name;
| >
| > // Set up all the properties of this control from the
parameter.properties
| >
| > foreach(DictionaryEntry de in parameter.Properties)
| >
| > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| >
| >
| > e.Item.Controls.Add(control);
| >
| > }
| >
| > catch (Exception ex)
| >
| > {
| >
| > throw new ApplicationException("Unable to render criteria. Reason: " +
| > ex.Message, ex);
| >
| > }
| >
| > }
| >
| > | > > In testing, i removed the main parent dropdown and only left the 2
below
| > it.
| > > this time, the same scenario happened...when the child dropdown list
| > > autopostsback, it's immediate parent's selectedindexchanged event
fires!
| I
| > 'm
| > > starting to pull my hair out now...I"m stuck!
| > >
| > > please help superman
| > >
| > > | > > > Another problem:
| > > >
| > > > while i'm waiting on your remark to my last post, i removed the sub
| > > > composite controls from my composite control so that there is only
| drop
| > > down
| > > > lists on it. During CreateChildcontrols, i load the main drop down
| using
| > > > databind. When the page is sent to browser for the first time, i
have
| my
| > > > main drop down filled. I then select an item and its
| > SelectedIndexChanged
| > > > fires and populates the send drop down list. Then when i select an
| item
| > > from
| > > > it, it posts back, and the event that gets called is the main(first)
| > > > dropdown list's SelectedIndexChanged event, which then re-populates
| the
| > > > second drop down list, then the control returns to the browser (The
| > > > SelectedIndexChanged event never fired for the 2nd dropdown's
changed
| > > > event.???
| > > >
| > > > thanks again
| > > >
| > > > using System;
| > > >
| > > > using System.Collections.Specialized;
| > > >
| > > > using System.Web.UI;
| > > >
| > > > using System.Web.UI.WebControls;
| > > >
| > > > using System.Text;
| > > >
| > > > using OperationsTeams.Business;
| > > >
| > > > using OperationsTeams.Data;
| > > >
| > > > using OperationsTeams.Reporting;
| > > >
| > > > using OperationsTeams.Reporting.WebControls;
| > > >
| > > > namespace OperationsTeams.Web.ReportControls
| > > >
| > > > {
| > > >
| > > > /// <summary>
| > > >
| > > > /// Summary description for FiscalAgentHierarchy.
| > > >
| > > > /// </summary>
| > > >
| > > > public class FiscalAgentHierarchy : WebControl,
| IReportParameterControl,
| > > > INamingContainer
| > > >
| > > > {
| > > >
| > > > 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
| > > >
| > > > protected override void OnLoad(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnLoad (e);
| > > >
| > > >
| > > > // The last state of controls from viewstate is now loaded (Before
the
| > > > client data is processed)
| > > >
| > > > }
| > > >
| > > >
| > > > protected override void OnPreRender(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnPreRender (e);
| > > >
| > > > // The controls now have the client values from the the last
postback
| > > >
| > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > > >
| > > > // ddlProviders.Visible = ProviderVisible;
| > > >
| > > > // ddlSites.Visible = SiteVisible;
| > > >
| > > > // ddlClasses.Visible = ClassVisible;
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > > // ddlSites.Visible = true;
| > > >
| > > > }
| > > >
| > > > 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 ddlFundingSource_SelectedIndexChanged(object sender,
| > > EventArgs
| > > > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlProviders_SelectedIndexChanged(object sender,
| EventArgs
| > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlSites_SelectedIndexChanged(object sender, EventArgs
e)
| > > >
| > > > {
| > > >
| > > > LoadClasses();
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > protected override void CreateChildControls()
| > > >
| > > > {
| > > >
| > > > this.ddlFundingSource = new DropDownList();
| > > >
| > > > this.ddlProviders = new DropDownList();
| > > >
| > > > this.ddlSites = new DropDownList();
| > > >
| > > > this.ddlClasses = new DropDownList();
| > > >
| > > > ddlFundingSource.ID = FundingSourceControlId;
| > > >
| > > > ddlProviders.ID = ProvidersControlId;
| > > >
| > > > ddlSites.ID = SitesControlId;
| > > >
| > > > ddlClasses.ID = ClassesControlId;
| > > >
| > > >
| > > > LoadProviders();
| > > >
| > > > // 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( said:
| > > > );
| > > >
| > > > 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( said:
| > > >
| > > > this.Controls.Add(ddlClasses);
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > // end containing table
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > ddlFundingSource.SelectedIndexChanged += new
| > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > > >
| > > > ddlProviders.SelectedIndexChanged += new
| > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > > >
| > > > ddlSites.SelectedIndexChanged += new
| > > > EventHandler(ddlSites_SelectedIndexChanged);
| > > >
| > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > > > ddlSites.AutoPostBack = true;
| > > >
| > > >
| > > > }
| > > >
| > > > private void LoadFundingSource()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = 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
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = false;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > private void LoadProviders()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > >
| > > >
| > > > ProviderVisible = true;
| > > >
| > > > // are these dates correct???????????????????????????
| > > >
| > > > ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
new
| > > > DateTime(2005,7,1), new
| > > >
| DateTime(2006,6,30));//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();
| > > >
| > > > ProviderVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadSites();
| > > >
| > > > }
| > > >
| > > > private void LoadSites()
| > > >
| > > > {
| > > >
| > > > if(ddlProviders.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > // Load the Site search parameters.
| > > >
| > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > > >
| > > > siteFindArgs.FiscalAgentId=1;
| > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > SiteVisible = 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();
| > > >
| > > > SiteVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadClasses();
| > > >
| > > > }
| > > >
| > > > private void LoadClasses()
| > > >
| > > > {
| > > >
| > > > if(ddlSites.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| AdultEdClassFindArgs();
| > > >
| > > > // adultEdClassFindArgs.FiscalAgentId =
| > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > > > rysReportingYearSelector.ReportingYearStartDate;
| > > >
| > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > > > rysReportingYearSelector.ReportingYearEndDate;
| > > >
| > > > // adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;
| > > >
| > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > > >
| > > >
| > > > ClassVisible = true;
| > > >
| > > > ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);
| > > >
| > > > ddlClasses.DataTextField = "Name";
| > > >
| > > > ddlClasses.DataValueField = "ClassId";
| > > >
| > > > ddlClasses.DataBind();
| > > >
| > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
string.Empty));
| > > >
| > > > }
| > > >
| > > > else
| > > >
| > > > {
| > > >
| > > > ddlClasses.Items.Clear();
| > > >
| > > > ClassVisible = 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
| > > >
| > > > protected bool FundingSourceVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["FundingSourceVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["FundingSourceVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["FundingSourceVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ProviderVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ProviderVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ProviderVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ProviderVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool SiteVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["SiteVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["SiteVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["SiteVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ClassVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ClassVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ClassVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ClassVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > #region Private Member Variables
| > > >
| > > > 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
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > >
| > > > | > > > > Hi TS,
| > > > >
| > > > > See you again :), seems you're rushing in a asp.net project these
| > days?
| > > > > For the question you mentioned in this post, here are some of my
| > > > > understanding and suggestions:
| > > > >
| > > > > 1. ASP.NET controls derived from Control will automatically
maintain
| > its
| > > > > ViewStates according to the asp.net web page's events sequence. So
| for
| > > > > composite control, those nested sub Controls' status (properties
| which
| > > be
| > > > > persistd in Viewsstate ) will be store and retrieve automatically.
| > > > >
| > > > > 2. However, there're some thing we need to care when building
| > composite
| > > > > control:
| > > > > #remember to implement INamingContainer for controls which will
have
| > > > nested
| > > > > sub controls. Otherwise, even handler mapping, ViewState loading
| will
| > > > occur
| > > > > unexpectedly.
| > > > >
| > > > > #Do remember to assign a explicit ID for each sub controls(same
| reason
| > > as
| > > > > #1). Also, please always try best to add subcontrols in the
| > > > > "CreateChildControls" method(just create control hierarchy) and
put
| > > > > manipulating code in postback event or PreRender event.
| > > > >
| > > > > In addition, for your detaile scenario, I've just built a very
| simple
| > > demo
| > > > > control which have three dropdownlists and The "Top" one will
| display
| > > > > first(other twos invisible) and according to the top one's
| selection,
| > > the
| > > > > "Mid" dropdownlist will be pouplated and the same when the "mid"'s
| > > > > selection changed......
| > > > >
| > > > > Here's the control's code for your reference:
| > > > >
| > > > > =========================
| > > > > [DefaultProperty("Text"),
| > > > > ToolboxData("<{0}:MultiListControl
| > > runat=server></{0}:MultiListControl>")]
| > > > > public class MultiListControl :
| System.Web.UI.WebControls.WebControl,
| > > > > INamingContainer
| > > > > {
| > > > > private string text;
| > > > >
| > > > > private DropDownList lstTop;
| > > > > private DropDownList lstMid;
| > > > > private DropDownList lstBot;
| > > > >
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > protected bool MidVisible
| > > > > {
| > > > > get{
| > > > > if(ViewState["MID_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["MID_VISIBLE"];
| > > > > }
| > > > >
| > > > > set{
| > > > > TrackViewState();
| > > > > ViewState["MID_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > > protected bool BotVisible
| > > > > {
| > > > > get
| > > > > {
| > > > > if(ViewState["BOT_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["BOT_VISIBLE"];
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > TrackViewState();
| > > > > ViewState["BOT_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > [Bindable(true),
| > > > > Category("Appearance"),
| > > > > DefaultValue("")]
| > > > > public string Text
| > > > > {
| > > > > get
| > > > > {
| > > > > return text;
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > text = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > protected override void CreateChildControls()
| > > > > {
| > > > > Controls.Clear();
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > <table width='100%'>
| > > > > <tr><td>
| > > > > "));
| > > > >
| > > > > lstTop = new DropDownList();
| > > > > lstTop.ID = "lstTop";
| > > > >
| > > > > lstTop.Items.Add("----------");
| > > > > lstTop.Items.Add("Top_Item_1");
| > > > > lstTop.Items.Add("Top_Item_2");
| > > > > lstTop.Items.Add("Top_Item_3");
| > > > > lstTop.Items.Add("Top_Item_4");
| > > > >
| > > > > Controls.Add(lstTop);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > > lstMid = new DropDownList();
| > > > > lstMid.ID = "lstMid";
| > > > >
| > > > > Controls.Add(lstMid);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > >
| > > > > lstBot = new DropDownList();
| > > > > lstBot.ID = "lstBot";
| > > > >
| > > > > Controls.Add(lstBot);
| > > > >
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > </td></tr>
| > > > > </table>
| > > > > "
| > > > > ));
| > > > >
| > > > >
| > > > >
| > > > > lstTop.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstMid.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstBot.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > >
| > > > > lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack =
| > true;
| > > > >
| > > > >
| > > > > }
| > > > >
| > > > >
| > > > > protected override void OnPreRender(EventArgs e)
| > > > > {
| > > > > base.OnPreRender (e);
| > > > >
| > > > > lstMid.Visible = MidVisible;
| > > > > lstBot.Visible = BotVisible;
| > > > > }
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > private void lst_SelectedIndexChanged(object sender,
| System.EventArgs
| > e)
| > > > > {
| > > > >
| > > > > DropDownList lst = sender as DropDownList;
| > > > >
| > > > > switch(lst.ID)
| > > > > {
| > > > > case "lstTop":
| > > > >
| > > > > if(lst.SelectedIndex != 0)
| > > > > {
| > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstMid.DataTextField = "Text";
| > > > > lstMid.DataValueField= "Value";
| > > > > lstMid.DataBind();
| > > > >
| > > > > MidVisible = true;
| > > > > }
| > > > > else
| > > > > {
| > > > > MidVisible = BotVisible = false;
| > > > > }
| > > > >
| > > > > break;
| > > > > case "lstMid":
| > > > >
| > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstBot.DataTextField = "Text";
| > > > > lstBot.DataValueField= "Value";
| > > > > lstBot.DataBind();
| > > > >
| > > > > MidVisible = BotVisible = true;
| > > > >
| > > > > break;
| > > > > case "lstBot":
| > > > >
| > > > >
| > > > >
| > > > > break;
| > > > > }
| > > > >
| > > > > Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
| > > > > lst.EnableViewState);
| > > > > }
| > > > >
| > > > > #region --Helper functions---
| > > > >
| > > > > public ListItemCollection GetSubItems(string parent)
| > > > > {
| > > > > ListItemCollection items = new ListItemCollection();
| > > > > int count = parent.Length;
| > > > >
| > > > > for(int i=0;i<count;++i)
| > > > > {
| > > > > items.Add(parent + "_Item_" + i);
| > > > > }
| > > > >
| > > > > return items;
| > > > > }
| > > > >
| > > > >
| > > > > #endregion
| > > > > }
| > > > >
| > > > > ========================
| > > > > Hope helps. Thanks,
| > > > >
| > > > > Steven Cheng
| > > > > Microsoft Online Support
| > > > >
| > > > > Get Secure! www.microsoft.com/security
| > > > > (This posting is provided "AS IS", with no warranties, and confers
| no
| > > > > rights.)
| > > > >
| > > > >
| > > > > --------------------
| > > > > | From: "TS" <[email protected]>
| > > > > | References: <[email protected]>
| > > > > | Subject: Re: explanation of when need to repopulate control
| > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > > > > | Lines: 39
| > > > > | X-Priority: 3
| > > > > | X-MSMail-Priority: Normal
| > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > > > > | Message-ID: <[email protected]>
| > > > > | Newsgroups:
| > > > >
| > > >
| > >
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > > > > framework.aspnet.buildingcontrols
| > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > > > > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > > > > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > > > > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > > > > |
| > > > > | sorry, heres the scenario i'm trying to accomplish:
| > > > > | I have a composite control that contains 4 drop down lists. When
| the
| > > > page
| > > > > | loads initially, i want the first drop down filled and the rest
| > > > invisible.
| > > > > | When you select an item in this ddl, it posts back to the server
| and
| > > > based
| > > > > | on its value, it populates its immediate child's drop down list.
| So
| > > now
| > > > > the
| > > > > | top ddl has a value selected and the 2nd one just has its items
| > > > populated.
| > > > > | Then when the 2nd drop down list gets selected, it posts to the
| > server
| > > > and
| > > > > | its value is used to populate(filter) the items for the 3rd drop
| > down
| > > > > | list...and so on for each drop down list.
| > > > > |
| > > > > | Please tell me what i need to do to handle post back data and
| > maintain
| > > > > state
| > > > > | from one postback to another while keeping the drop downlists
| filled
| > > and
| > > > > | their values persisted.
| > > > > |
| > > > > | thank you again!
| > > > > |
| > > > > |
| > > > > | | > > > > | > I have a quesiton:
| > > > > | > if i have a composite control and on its intial page loading,
i
| > fill
| > > > my
| > > > > | (sub
| > > > > | > control) drop down list's items collection from the database
and
| > > > return.
| > > > > | > When the user hits a button to cause postback, the control is
| > going
| > > to
| > > > > get
| > > > > | > initialized, then does its items collection that i filled on
the
| > > > initial
| > > > > | > page request get repopulated from viewstate? And on top of
that,
| > if
| > > > so,
| > > > > | does
| > > > > | > the list item that person selected in the drop down list again
| set
| > > > > itself
| > > > > | as
| > > > > | > the selected item in the list?
| > > > > | >
| > > > > | > OR do i have to re-load the items on every page request and
then
| > > > > populate
| > > > > | > its value some other way???
| > > > > | >
| > > > > | > thanks a bunch
| > > > > | >
| > > > > | >
| > > > > |
| > > > > |
| > > > > |
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|
 
T

TS

I have a new problem now. I have figured out that the cause is the same
reason. If its in the custom DataList, it doesn't work, else it does work.

The scenario:
After the initial page load, you enter data into controls and hit submit
button, the process is as follows:
Page_Load
DataList's OnLoad
Composite Control's OnLoad
Submit button's OnClick - At this point, the controls in the composite
control have no listitems and no selectedValue properties.

I have statically added the composite control onto the same page as the
dynamic one, so here is the process in this scenario:
Page_Load
Composite Control's OnLoad (The one whose parent is Page)
DataList's OnLoad
Composite Control's OnLoad (The one whose parent is the Custom DataList)
Submit button's OnClick - At this point, the controls in the statically
declared composite control have listitems and have values for selectedValue
properties.

So the same control at the same time - the one outside the custom Datalist
has its controls' state set up correctly, the ones inside does not.

So the same reason is at play here. Maybe since i am dynamically creating
the class using reflection (Assembly.CreateInstance()) that has something to
do with it?

Please help mr. Cheng.

Thank you very much!

TS



Steven Cheng said:
Hi TS,

First, I'm glad that you've got your composite control work, all the
dropdownlist's postback events can fire correctly,yes?

As for the new problem you encountered when adding your composite control
into DataList's item, is the DataList the asp.net's buildin DataList
control? And since you mentioned that you dynamically add your control
into it, how do you dynamically add your custom control? Will there occur
problem if you statically add your control into DataList?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Wed, 3 Aug 2005 19:07:16 -0500
| Lines: 1153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well Steve, I am almost done. My control works well, except its not in the
| framework i just mentioned. Adding my control dynamically to the
datalist's
| item may be the root of the cause. i've made sure all custom controls
| implmenet INamingContainer & I think all controls have their id's set, so
| what else can i do?
|
| thanks a bunch
|
| | > I have figured the cause of the problem, sort of. My main control was
| being
| > loaded dynamically during a custom data list control's ItemDataBound
| event,
| > and then added to the e.item.controls collection. Once I removed it from
| > here, the correct event was called in my control. the problem is i need
to
| > keep it where it is because of the way the page works.
| >
| > I tried to add INamingContainer to the custom Datalist, but that didn't
| > help. Any ideas what could make this happen?
| >
| > thanks so much, i know i'm being a pain, but i'm stuck!
| >
| > This is the custom DataLists' event:
| > protected override void OnItemDataBound(DataListItemEventArgs e)
| >
| > {
| >
| > base.OnItemDataBound(e);
| >
| > Parameter parameter = (Parameter)e.Item.DataItem;
| >
| > try
| >
| > {
| >
| > Control control;
| >
| > if(parameter.Type == ParameterType.Control)
| >
| > control = this.Page.LoadControl(parameter.ControlPath);
| >
| > else
| >
| > {
| >
| > Assembly assembly = parameter.Assembly;
| >
| > if(assembly == null)
| >
| > {
| >
| > // The control didn't declare its own assembly, so use the report's
| > ControlsAssembly
| >
| > assembly = this.ControlsAssembly;
| >
| > // Ther report's ControlsAssembly is null, so use current page's
assembly
| >
| > if(assembly == null)
| >
| > assembly = this.Page.GetType().BaseType.Assembly;
| >
| > }
| >
| >
| > control = (Control) assembly.CreateInstance(parameter.ControlTypeName);
| >
| > }
| >
| > control.ID = parameter.Name;
| >
| > // Set up all the properties of this control from the
parameter.properties
| >
| > foreach(DictionaryEntry de in parameter.Properties)
| >
| > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| >
| >
| > e.Item.Controls.Add(control);
| >
| > }
| >
| > catch (Exception ex)
| >
| > {
| >
| > throw new ApplicationException("Unable to render criteria. Reason: " +
| > ex.Message, ex);
| >
| > }
| >
| > }
| >
| > | > > In testing, i removed the main parent dropdown and only left the 2
below
| > it.
| > > this time, the same scenario happened...when the child dropdown list
| > > autopostsback, it's immediate parent's selectedindexchanged event
fires!
| I
| > 'm
| > > starting to pull my hair out now...I"m stuck!
| > >
| > > please help superman
| > >
| > > | > > > Another problem:
| > > >
| > > > while i'm waiting on your remark to my last post, i removed the sub
| > > > composite controls from my composite control so that there is only
| drop
| > > down
| > > > lists on it. During CreateChildcontrols, i load the main drop down
| using
| > > > databind. When the page is sent to browser for the first time, i
have
| my
| > > > main drop down filled. I then select an item and its
| > SelectedIndexChanged
| > > > fires and populates the send drop down list. Then when i select an
| item
| > > from
| > > > it, it posts back, and the event that gets called is the main(first)
| > > > dropdown list's SelectedIndexChanged event, which then re-populates
| the
| > > > second drop down list, then the control returns to the browser (The
| > > > SelectedIndexChanged event never fired for the 2nd dropdown's
changed
| > > > event.???
| > > >
| > > > thanks again
| > > >
| > > > using System;
| > > >
| > > > using System.Collections.Specialized;
| > > >
| > > > using System.Web.UI;
| > > >
| > > > using System.Web.UI.WebControls;
| > > >
| > > > using System.Text;
| > > >
| > > > using OperationsTeams.Business;
| > > >
| > > > using OperationsTeams.Data;
| > > >
| > > > using OperationsTeams.Reporting;
| > > >
| > > > using OperationsTeams.Reporting.WebControls;
| > > >
| > > > namespace OperationsTeams.Web.ReportControls
| > > >
| > > > {
| > > >
| > > > /// <summary>
| > > >
| > > > /// Summary description for FiscalAgentHierarchy.
| > > >
| > > > /// </summary>
| > > >
| > > > public class FiscalAgentHierarchy : WebControl,
| IReportParameterControl,
| > > > INamingContainer
| > > >
| > > > {
| > > >
| > > > 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
| > > >
| > > > protected override void OnLoad(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnLoad (e);
| > > >
| > > >
| > > > // The last state of controls from viewstate is now loaded (Before
the
| > > > client data is processed)
| > > >
| > > > }
| > > >
| > > >
| > > > protected override void OnPreRender(EventArgs e)
| > > >
| > > > {
| > > >
| > > > base.OnPreRender (e);
| > > >
| > > > // The controls now have the client values from the the last
postback
| > > >
| > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > > >
| > > > // ddlProviders.Visible = ProviderVisible;
| > > >
| > > > // ddlSites.Visible = SiteVisible;
| > > >
| > > > // ddlClasses.Visible = ClassVisible;
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > > // ddlSites.Visible = true;
| > > >
| > > > }
| > > >
| > > > 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 ddlFundingSource_SelectedIndexChanged(object sender,
| > > EventArgs
| > > > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlProviders_SelectedIndexChanged(object sender,
| EventArgs
| > e)
| > > >
| > > > {
| > > >
| > > > LoadSites();
| > > >
| > > > }
| > > >
| > > > private void ddlSites_SelectedIndexChanged(object sender, EventArgs
e)
| > > >
| > > > {
| > > >
| > > > LoadClasses();
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > protected override void CreateChildControls()
| > > >
| > > > {
| > > >
| > > > this.ddlFundingSource = new DropDownList();
| > > >
| > > > this.ddlProviders = new DropDownList();
| > > >
| > > > this.ddlSites = new DropDownList();
| > > >
| > > > this.ddlClasses = new DropDownList();
| > > >
| > > > ddlFundingSource.ID = FundingSourceControlId;
| > > >
| > > > ddlProviders.ID = ProvidersControlId;
| > > >
| > > > ddlSites.ID = SitesControlId;
| > > >
| > > > ddlClasses.ID = ClassesControlId;
| > > >
| > > >
| > > > LoadProviders();
| > > >
| > > > // 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( said:
| > > > );
| > > >
| > > > 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( said:
| > > >
| > > > this.Controls.Add(ddlClasses);
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > // end containing table
| > > >
| > > > this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > > >
| > > > ddlFundingSource.SelectedIndexChanged += new
| > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > > >
| > > > ddlProviders.SelectedIndexChanged += new
| > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > > >
| > > > ddlSites.SelectedIndexChanged += new
| > > > EventHandler(ddlSites_SelectedIndexChanged);
| > > >
| > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > > > ddlSites.AutoPostBack = true;
| > > >
| > > >
| > > > }
| > > >
| > > > private void LoadFundingSource()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = 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
| > > >
| > > > {
| > > >
| > > > FundingSourceVisible = false;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > private void LoadProviders()
| > > >
| > > > {
| > > >
| > > > int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;
| > > >
| > > > if(fiscalAgentId != int.MinValue)
| > > >
| > > > {
| > > >
| > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > > >
| > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > > >
| > > >
| > > >
| > > > ProviderVisible = true;
| > > >
| > > > // are these dates correct???????????????????????????
| > > >
| > > > ddlProviders.DataSource = FiscalAgentProvider.Find(fiscalAgentId,
new
| > > > DateTime(2005,7,1), new
| > > >
| DateTime(2006,6,30));//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();
| > > >
| > > > ProviderVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadSites();
| > > >
| > > > }
| > > >
| > > > private void LoadSites()
| > > >
| > > > {
| > > >
| > > > if(ddlProviders.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > // Load the Site search parameters.
| > > >
| > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > > >
| > > > siteFindArgs.FiscalAgentId=1;
| > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > SiteVisible = 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();
| > > >
| > > > SiteVisible = false;
| > > >
| > > > }
| > > >
| > > > // LoadClasses();
| > > >
| > > > }
| > > >
| > > > private void LoadClasses()
| > > >
| > > > {
| > > >
| > > > if(ddlSites.SelectedValue != string.Empty)
| > > >
| > > > {
| > > >
| > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| AdultEdClassFindArgs();
| > > >
| > > > // adultEdClassFindArgs.FiscalAgentId =
| > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > > >
| > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > > > rysReportingYearSelector.ReportingYearStartDate;
| > > >
| > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > > > rysReportingYearSelector.ReportingYearEndDate;
| > > >
| > > > // adultEdClassFindArgs.ProviderName = ddlProviders.SelectedValue;
| > > >
| > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > > >
| > > >
| > > > ClassVisible = true;
| > > >
| > > > ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);
| > > >
| > > > ddlClasses.DataTextField = "Name";
| > > >
| > > > ddlClasses.DataValueField = "ClassId";
| > > >
| > > > ddlClasses.DataBind();
| > > >
| > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
string.Empty));
| > > >
| > > > }
| > > >
| > > > else
| > > >
| > > > {
| > > >
| > > > ddlClasses.Items.Clear();
| > > >
| > > > ClassVisible = 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
| > > >
| > > > protected bool FundingSourceVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["FundingSourceVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["FundingSourceVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["FundingSourceVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ProviderVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ProviderVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ProviderVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ProviderVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool SiteVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["SiteVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["SiteVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["SiteVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > protected bool ClassVisible
| > > >
| > > > {
| > > >
| > > > get
| > > >
| > > > {
| > > >
| > > > if(ViewState["ClassVisible"] == null)
| > > >
| > > > {
| > > >
| > > > return false;
| > > >
| > > > }
| > > >
| > > > return (bool)ViewState["ClassVisible"];
| > > >
| > > > }
| > > >
| > > > set
| > > >
| > > > {
| > > >
| > > > TrackViewState();
| > > >
| > > > ViewState["ClassVisible"] = value;
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > > #endregion
| > > >
| > > > #region Private Member Variables
| > > >
| > > > 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
| > > >
| > > > }
| > > >
| > > > }
| > > >
| > > >
| > > > | > > > > Hi TS,
| > > > >
| > > > > See you again :), seems you're rushing in a asp.net project these
| > days?
| > > > > For the question you mentioned in this post, here are some of my
| > > > > understanding and suggestions:
| > > > >
| > > > > 1. ASP.NET controls derived from Control will automatically
maintain
| > its
| > > > > ViewStates according to the asp.net web page's events sequence. So
| for
| > > > > composite control, those nested sub Controls' status (properties
| which
| > > be
| > > > > persistd in Viewsstate ) will be store and retrieve automatically.
| > > > >
| > > > > 2. However, there're some thing we need to care when building
| > composite
| > > > > control:
| > > > > #remember to implement INamingContainer for controls which will
have
| > > > nested
| > > > > sub controls. Otherwise, even handler mapping, ViewState loading
| will
| > > > occur
| > > > > unexpectedly.
| > > > >
| > > > > #Do remember to assign a explicit ID for each sub controls(same
| reason
| > > as
| > > > > #1). Also, please always try best to add subcontrols in the
| > > > > "CreateChildControls" method(just create control hierarchy) and
put
| > > > > manipulating code in postback event or PreRender event.
| > > > >
| > > > > In addition, for your detaile scenario, I've just built a very
| simple
| > > demo
| > > > > control which have three dropdownlists and The "Top" one will
| display
| > > > > first(other twos invisible) and according to the top one's
| selection,
| > > the
| > > > > "Mid" dropdownlist will be pouplated and the same when the "mid"'s
| > > > > selection changed......
| > > > >
| > > > > Here's the control's code for your reference:
| > > > >
| > > > > =========================
| > > > > [DefaultProperty("Text"),
| > > > > ToolboxData("<{0}:MultiListControl
| > > runat=server></{0}:MultiListControl>")]
| > > > > public class MultiListControl :
| System.Web.UI.WebControls.WebControl,
| > > > > INamingContainer
| > > > > {
| > > > > private string text;
| > > > >
| > > > > private DropDownList lstTop;
| > > > > private DropDownList lstMid;
| > > > > private DropDownList lstBot;
| > > > >
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > protected bool MidVisible
| > > > > {
| > > > > get{
| > > > > if(ViewState["MID_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["MID_VISIBLE"];
| > > > > }
| > > > >
| > > > > set{
| > > > > TrackViewState();
| > > > > ViewState["MID_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > > protected bool BotVisible
| > > > > {
| > > > > get
| > > > > {
| > > > > if(ViewState["BOT_VISIBLE"] == null)
| > > > > {
| > > > > return false;
| > > > > }
| > > > >
| > > > > return (bool)ViewState["BOT_VISIBLE"];
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > TrackViewState();
| > > > > ViewState["BOT_VISIBLE"] = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > [Bindable(true),
| > > > > Category("Appearance"),
| > > > > DefaultValue("")]
| > > > > public string Text
| > > > > {
| > > > > get
| > > > > {
| > > > > return text;
| > > > > }
| > > > >
| > > > > set
| > > > > {
| > > > > text = value;
| > > > > }
| > > > > }
| > > > >
| > > > >
| > > > > protected override void CreateChildControls()
| > > > > {
| > > > > Controls.Clear();
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > <table width='100%'>
| > > > > <tr><td>
| > > > > "));
| > > > >
| > > > > lstTop = new DropDownList();
| > > > > lstTop.ID = "lstTop";
| > > > >
| > > > > lstTop.Items.Add("----------");
| > > > > lstTop.Items.Add("Top_Item_1");
| > > > > lstTop.Items.Add("Top_Item_2");
| > > > > lstTop.Items.Add("Top_Item_3");
| > > > > lstTop.Items.Add("Top_Item_4");
| > > > >
| > > > > Controls.Add(lstTop);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > > lstMid = new DropDownList();
| > > > > lstMid.ID = "lstMid";
| > > > >
| > > > > Controls.Add(lstMid);
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"<br/>"
| > > > > ));
| > > > >
| > > > >
| > > > > lstBot = new DropDownList();
| > > > > lstBot.ID = "lstBot";
| > > > >
| > > > > Controls.Add(lstBot);
| > > > >
| > > > >
| > > > > Controls.Add(
| > > > > new LiteralControl(
| > > > > @"
| > > > > </td></tr>
| > > > > </table>
| > > > > "
| > > > > ));
| > > > >
| > > > >
| > > > >
| > > > > lstTop.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstMid.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > > lstBot.SelectedIndexChanged +=new
| > > EventHandler(lst_SelectedIndexChanged);
| > > > >
| > > > > lstTop.AutoPostBack = lstMid.AutoPostBack = lstBot.AutoPostBack =
| > true;
| > > > >
| > > > >
| > > > > }
| > > > >
| > > > >
| > > > > protected override void OnPreRender(EventArgs e)
| > > > > {
| > > > > base.OnPreRender (e);
| > > > >
| > > > > lstMid.Visible = MidVisible;
| > > > > lstBot.Visible = BotVisible;
| > > > > }
| > > > >
| > > > >
| > > > >
| > > > >
| > > > > private void lst_SelectedIndexChanged(object sender,
| System.EventArgs
| > e)
| > > > > {
| > > > >
| > > > > DropDownList lst = sender as DropDownList;
| > > > >
| > > > > switch(lst.ID)
| > > > > {
| > > > > case "lstTop":
| > > > >
| > > > > if(lst.SelectedIndex != 0)
| > > > > {
| > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstMid.DataTextField = "Text";
| > > > > lstMid.DataValueField= "Value";
| > > > > lstMid.DataBind();
| > > > >
| > > > > MidVisible = true;
| > > > > }
| > > > > else
| > > > > {
| > > > > MidVisible = BotVisible = false;
| > > > > }
| > > > >
| > > > > break;
| > > > > case "lstMid":
| > > > >
| > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > > > > lstBot.DataTextField = "Text";
| > > > > lstBot.DataValueField= "Value";
| > > > > lstBot.DataBind();
| > > > >
| > > > > MidVisible = BotVisible = true;
| > > > >
| > > > > break;
| > > > > case "lstBot":
| > > > >
| > > > >
| > > > >
| > > > > break;
| > > > > }
| > > > >
| > > > > Page.Response.Write("<br>" + lst.ID + "_selectedindexchanged!" +
| > > > > lst.EnableViewState);
| > > > > }
| > > > >
| > > > > #region --Helper functions---
| > > > >
| > > > > public ListItemCollection GetSubItems(string parent)
| > > > > {
| > > > > ListItemCollection items = new ListItemCollection();
| > > > > int count = parent.Length;
| > > > >
| > > > > for(int i=0;i<count;++i)
| > > > > {
| > > > > items.Add(parent + "_Item_" + i);
| > > > > }
| > > > >
| > > > > return items;
| > > > > }
| > > > >
| > > > >
| > > > > #endregion
| > > > > }
| > > > >
| > > > > ========================
| > > > > Hope helps. Thanks,
| > > > >
| > > > > Steven Cheng
| > > > > Microsoft Online Support
| > > > >
| > > > > Get Secure! www.microsoft.com/security
| > > > > (This posting is provided "AS IS", with no warranties, and confers
| no
| > > > > rights.)
| > > > >
| > > > >
| > > > > --------------------
| > > > > | From: "TS" <[email protected]>
| > > > > | References: <[email protected]>
| > > > > | Subject: Re: explanation of when need to repopulate control
| > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > > > > | Lines: 39
| > > > > | X-Priority: 3
| > > > > | X-MSMail-Priority: Normal
| > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > > > > | Message-ID: <[email protected]>
| > > > > | Newsgroups:
| > > > >
| > > >
| > >
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > > > > framework.aspnet.buildingcontrols
| > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > > > > | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > > > > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > > > > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > > > > |
| > > > > | sorry, heres the scenario i'm trying to accomplish:
| > > > > | I have a composite control that contains 4 drop down lists. When
| the
| > > > page
| > > > > | loads initially, i want the first drop down filled and the rest
| > > > invisible.
| > > > > | When you select an item in this ddl, it posts back to the server
| and
| > > > based
| > > > > | on its value, it populates its immediate child's drop down list.
| So
| > > now
| > > > > the
| > > > > | top ddl has a value selected and the 2nd one just has its items
| > > > populated.
| > > > > | Then when the 2nd drop down list gets selected, it posts to the
| > server
| > > > and
| > > > > | its value is used to populate(filter) the items for the 3rd drop
| > down
| > > > > | list...and so on for each drop down list.
| > > > > |
| > > > > | Please tell me what i need to do to handle post back data and
| > maintain
| > > > > state
| > > > > | from one postback to another while keeping the drop downlists
| filled
| > > and
| > > > > | their values persisted.
| > > > > |
| > > > > | thank you again!
| > > > > |
| > > > > |
| > > > > | | > > > > | > I have a quesiton:
| > > > > | > if i have a composite control and on its intial page loading,
i
| > fill
| > > > my
| > > > > | (sub
| > > > > | > control) drop down list's items collection from the database
and
| > > > return.
| > > > > | > When the user hits a button to cause postback, the control is
| > going
| > > to
| > > > > get
| > > > > | > initialized, then does its items collection that i filled on
the
| > > > initial
| > > > > | > page request get repopulated from viewstate? And on top of
that,
| > if
| > > > so,
| > > > > | does
| > > > > | > the list item that person selected in the drop down list again
| set
| > > > > itself
| > > > > | as
| > > > > | > the selected item in the list?
| > > > > | >
| > > > > | > OR do i have to re-load the items on every page request and
then
| > > > > populate
| > > > > | > its value some other way???
| > > > > | >
| > > > > | > thanks a bunch
| > > > > | >
| > > > > | >
| > > > > |
| > > > > |
| > > > > |
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|
 
S

Steven Cheng[MSFT]

Thanks for your followup TS.

So can I say that currently your custom webcontrol(not template list
control) can correctly be added both statically and dynamically in the
normal DataList or Repeater controls (asp.net buildin ) , but have some
problem for postback events when added in your custom list control?

If so, we should keep focus on the custom datalist control. Has it any
problems when we nest some asp.net buildin controls in it? Would you try
making a simplified version of your custom datalist control so that we can
have a view to see whether there is anything wrong in it. Also, it'll be
helpful you also provide the complete code that you dynamically add control
into the datalist (through reflection).

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Fri, 5 Aug 2005 17:19:23 -0500
| Lines: 1298
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4003
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| I have a new problem now. I have figured out that the cause is the same
| reason. If its in the custom DataList, it doesn't work, else it does work.
|
| The scenario:
| After the initial page load, you enter data into controls and hit submit
| button, the process is as follows:
| Page_Load
| DataList's OnLoad
| Composite Control's OnLoad
| Submit button's OnClick - At this point, the controls in the composite
| control have no listitems and no selectedValue properties.
|
| I have statically added the composite control onto the same page as the
| dynamic one, so here is the process in this scenario:
| Page_Load
| Composite Control's OnLoad (The one whose parent is Page)
| DataList's OnLoad
| Composite Control's OnLoad (The one whose parent is the Custom DataList)
| Submit button's OnClick - At this point, the controls in the statically
| declared composite control have listitems and have values for
selectedValue
| properties.
|
| So the same control at the same time - the one outside the custom Datalist
| has its controls' state set up correctly, the ones inside does not.
|
| So the same reason is at play here. Maybe since i am dynamically creating
| the class using reflection (Assembly.CreateInstance()) that has something
to
| do with it?
|
| Please help mr. Cheng.
|
| Thank you very much!
|
| TS
|
|
|
| | > Hi TS,
| >
| > First, I'm glad that you've got your composite control work, all the
| > dropdownlist's postback events can fire correctly,yes?
| >
| > As for the new problem you encountered when adding your composite
control
| > into DataList's item, is the DataList the asp.net's buildin DataList
| > control? And since you mentioned that you dynamically add your control
| > into it, how do you dynamically add your custom control? Will there
occur
| > problem if you statically add your control into DataList?
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "TS" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <unRs#[email protected]>
| > <[email protected]>
| > | Subject: Re: explanation of when need to repopulate control
| > | Date: Wed, 3 Aug 2005 19:07:16 -0500
| > | Lines: 1153
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | Well Steve, I am almost done. My control works well, except its not in
| the
| > | framework i just mentioned. Adding my control dynamically to the
| > datalist's
| > | item may be the root of the cause. i've made sure all custom controls
| > | implmenet INamingContainer & I think all controls have their id's set,
| so
| > | what else can i do?
| > |
| > | thanks a bunch
| > |
| > | | > | > I have figured the cause of the problem, sort of. My main control
was
| > | being
| > | > loaded dynamically during a custom data list control's ItemDataBound
| > | event,
| > | > and then added to the e.item.controls collection. Once I removed it
| from
| > | > here, the correct event was called in my control. the problem is i
| need
| > to
| > | > keep it where it is because of the way the page works.
| > | >
| > | > I tried to add INamingContainer to the custom Datalist, but that
| didn't
| > | > help. Any ideas what could make this happen?
| > | >
| > | > thanks so much, i know i'm being a pain, but i'm stuck!
| > | >
| > | > This is the custom DataLists' event:
| > | > protected override void OnItemDataBound(DataListItemEventArgs e)
| > | >
| > | > {
| > | >
| > | > base.OnItemDataBound(e);
| > | >
| > | > Parameter parameter = (Parameter)e.Item.DataItem;
| > | >
| > | > try
| > | >
| > | > {
| > | >
| > | > Control control;
| > | >
| > | > if(parameter.Type == ParameterType.Control)
| > | >
| > | > control = this.Page.LoadControl(parameter.ControlPath);
| > | >
| > | > else
| > | >
| > | > {
| > | >
| > | > Assembly assembly = parameter.Assembly;
| > | >
| > | > if(assembly == null)
| > | >
| > | > {
| > | >
| > | > // The control didn't declare its own assembly, so use the report's
| > | > ControlsAssembly
| > | >
| > | > assembly = this.ControlsAssembly;
| > | >
| > | > // Ther report's ControlsAssembly is null, so use current page's
| > assembly
| > | >
| > | > if(assembly == null)
| > | >
| > | > assembly = this.Page.GetType().BaseType.Assembly;
| > | >
| > | > }
| > | >
| > | >
| > | > control = (Control)
| assembly.CreateInstance(parameter.ControlTypeName);
| > | >
| > | > }
| > | >
| > | > control.ID = parameter.Name;
| > | >
| > | > // Set up all the properties of this control from the
| > parameter.properties
| > | >
| > | > foreach(DictionaryEntry de in parameter.Properties)
| > | >
| > | > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| > | >
| > | >
| > | > e.Item.Controls.Add(control);
| > | >
| > | > }
| > | >
| > | > catch (Exception ex)
| > | >
| > | > {
| > | >
| > | > throw new ApplicationException("Unable to render criteria. Reason:
" +
| > | > ex.Message, ex);
| > | >
| > | > }
| > | >
| > | > }
| > | >
| > | > | > | > > In testing, i removed the main parent dropdown and only left the 2
| > below
| > | > it.
| > | > > this time, the same scenario happened...when the child dropdown
list
| > | > > autopostsback, it's immediate parent's selectedindexchanged event
| > fires!
| > | I
| > | > 'm
| > | > > starting to pull my hair out now...I"m stuck!
| > | > >
| > | > > please help superman
| > | > >
| > | > > | > | > > > Another problem:
| > | > > >
| > | > > > while i'm waiting on your remark to my last post, i removed the
| sub
| > | > > > composite controls from my composite control so that there is
only
| > | drop
| > | > > down
| > | > > > lists on it. During CreateChildcontrols, i load the main drop
down
| > | using
| > | > > > databind. When the page is sent to browser for the first time, i
| > have
| > | my
| > | > > > main drop down filled. I then select an item and its
| > | > SelectedIndexChanged
| > | > > > fires and populates the send drop down list. Then when i select
an
| > | item
| > | > > from
| > | > > > it, it posts back, and the event that gets called is the
| main(first)
| > | > > > dropdown list's SelectedIndexChanged event, which then
| re-populates
| > | the
| > | > > > second drop down list, then the control returns to the browser
| (The
| > | > > > SelectedIndexChanged event never fired for the 2nd dropdown's
| > changed
| > | > > > event.???
| > | > > >
| > | > > > thanks again
| > | > > >
| > | > > > using System;
| > | > > >
| > | > > > using System.Collections.Specialized;
| > | > > >
| > | > > > using System.Web.UI;
| > | > > >
| > | > > > using System.Web.UI.WebControls;
| > | > > >
| > | > > > using System.Text;
| > | > > >
| > | > > > using OperationsTeams.Business;
| > | > > >
| > | > > > using OperationsTeams.Data;
| > | > > >
| > | > > > using OperationsTeams.Reporting;
| > | > > >
| > | > > > using OperationsTeams.Reporting.WebControls;
| > | > > >
| > | > > > namespace OperationsTeams.Web.ReportControls
| > | > > >
| > | > > > {
| > | > > >
| > | > > > /// <summary>
| > | > > >
| > | > > > /// Summary description for FiscalAgentHierarchy.
| > | > > >
| > | > > > /// </summary>
| > | > > >
| > | > > > public class FiscalAgentHierarchy : WebControl,
| > | IReportParameterControl,
| > | > > > INamingContainer
| > | > > >
| > | > > > {
| > | > > >
| > | > > > 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
| > | > > >
| > | > > > protected override void OnLoad(EventArgs e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > base.OnLoad (e);
| > | > > >
| > | > > >
| > | > > > // The last state of controls from viewstate is now loaded
(Before
| > the
| > | > > > client data is processed)
| > | > > >
| > | > > > }
| > | > > >
| > | > > >
| > | > > > protected override void OnPreRender(EventArgs e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > base.OnPreRender (e);
| > | > > >
| > | > > > // The controls now have the client values from the the last
| > postback
| > | > > >
| > | > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > | > > >
| > | > > > // ddlProviders.Visible = ProviderVisible;
| > | > > >
| > | > > > // ddlSites.Visible = SiteVisible;
| > | > > >
| > | > > > // ddlClasses.Visible = ClassVisible;
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > > >
| > | > > > // ddlSites.Visible = true;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > 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 ddlFundingSource_SelectedIndexChanged(object
sender,
| > | > > EventArgs
| > | > > > e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > LoadSites();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void ddlProviders_SelectedIndexChanged(object sender,
| > | EventArgs
| > | > e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > LoadSites();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void ddlSites_SelectedIndexChanged(object sender,
| EventArgs
| > e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > LoadClasses();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > #endregion
| > | > > >
| > | > > > protected override void CreateChildControls()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > this.ddlFundingSource = new DropDownList();
| > | > > >
| > | > > > this.ddlProviders = new DropDownList();
| > | > > >
| > | > > > this.ddlSites = new DropDownList();
| > | > > >
| > | > > > this.ddlClasses = new DropDownList();
| > | > > >
| > | > > > ddlFundingSource.ID = FundingSourceControlId;
| > | > > >
| > | > > > ddlProviders.ID = ProvidersControlId;
| > | > > >
| > | > > > ddlSites.ID = SitesControlId;
| > | > > >
| > | > > > ddlClasses.ID = ClassesControlId;
| > | > > >
| > | > > >
| > | > > > LoadProviders();
| > | > > >
| > | > > > // 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>"));
| > | > > >
| > | > > > ddlFundingSource.SelectedIndexChanged += new
| > | > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > | > > >
| > | > > > ddlProviders.SelectedIndexChanged += new
| > | > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > | > > >
| > | > > > ddlSites.SelectedIndexChanged += new
| > | > > > EventHandler(ddlSites_SelectedIndexChanged);
| > | > > >
| > | > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > | > > > ddlSites.AutoPostBack = true;
| > | > > >
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadFundingSource()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > int fiscalAgentId =
1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > | > > >
| > | > > >
| > | > > > if(fiscalAgentId != int.MinValue)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > FundingSourceVisible = 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
| > | > > >
| > | > > > {
| > | > > >
| > | > > > FundingSourceVisible = false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadProviders()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;
| > | > > >
| > | > > > if(fiscalAgentId != int.MinValue)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > > >
| > | > > >
| > | > > >
| > | > > > ProviderVisible = true;
| > | > > >
| > | > > > // are these dates correct???????????????????????????
| > | > > >
| > | > > > ddlProviders.DataSource =
FiscalAgentProvider.Find(fiscalAgentId,
| > new
| > | > > > DateTime(2005,7,1), new
| > | > > >
| > |
DateTime(2006,6,30));//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();
| > | > > >
| > | > > > ProviderVisible = false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > // LoadSites();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadSites()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ddlProviders.SelectedValue != string.Empty)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > // Load the Site search parameters.
| > | > > >
| > | > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > | > > >
| > | > > > siteFindArgs.FiscalAgentId=1;
| > | > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > > >
| > | > > > SiteVisible = 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();
| > | > > >
| > | > > > SiteVisible = false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > // LoadClasses();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadClasses()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ddlSites.SelectedValue != string.Empty)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| > | AdultEdClassFindArgs();
| > | > > >
| > | > > > // adultEdClassFindArgs.FiscalAgentId =
| > | > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > > >
| > | > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > | > > > rysReportingYearSelector.ReportingYearStartDate;
| > | > > >
| > | > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > | > > > rysReportingYearSelector.ReportingYearEndDate;
| > | > > >
| > | > > > // adultEdClassFindArgs.ProviderName =
ddlProviders.SelectedValue;
| > | > > >
| > | > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > | > > >
| > | > > >
| > | > > > ClassVisible = true;
| > | > > >
| > | > > > ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);
| > | > > >
| > | > > > ddlClasses.DataTextField = "Name";
| > | > > >
| > | > > > ddlClasses.DataValueField = "ClassId";
| > | > > >
| > | > > > ddlClasses.DataBind();
| > | > > >
| > | > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
| > string.Empty));
| > | > > >
| > | > > > }
| > | > > >
| > | > > > else
| > | > > >
| > | > > > {
| > | > > >
| > | > > > ddlClasses.Items.Clear();
| > | > > >
| > | > > > ClassVisible = 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
| > | > > >
| > | > > > protected bool FundingSourceVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["FundingSourceVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["FundingSourceVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["FundingSourceVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > protected bool ProviderVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["ProviderVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["ProviderVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["ProviderVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > protected bool SiteVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["SiteVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["SiteVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["SiteVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > protected bool ClassVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["ClassVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["ClassVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["ClassVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > #endregion
| > | > > >
| > | > > > #region Private Member Variables
| > | > > >
| > | > > > 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
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > >
| message
| > | > > > | > | > > > > Hi TS,
| > | > > > >
| > | > > > > See you again :), seems you're rushing in a asp.net project
| these
| > | > days?
| > | > > > > For the question you mentioned in this post, here are some of
my
| > | > > > > understanding and suggestions:
| > | > > > >
| > | > > > > 1. ASP.NET controls derived from Control will automatically
| > maintain
| > | > its
| > | > > > > ViewStates according to the asp.net web page's events
sequence.
| So
| > | for
| > | > > > > composite control, those nested sub Controls' status
(properties
| > | which
| > | > > be
| > | > > > > persistd in Viewsstate ) will be store and retrieve
| automatically.
| > | > > > >
| > | > > > > 2. However, there're some thing we need to care when building
| > | > composite
| > | > > > > control:
| > | > > > > #remember to implement INamingContainer for controls which
will
| > have
| > | > > > nested
| > | > > > > sub controls. Otherwise, even handler mapping, ViewState
loading
| > | will
| > | > > > occur
| > | > > > > unexpectedly.
| > | > > > >
| > | > > > > #Do remember to assign a explicit ID for each sub
controls(same
| > | reason
| > | > > as
| > | > > > > #1). Also, please always try best to add subcontrols in the
| > | > > > > "CreateChildControls" method(just create control hierarchy)
and
| > put
| > | > > > > manipulating code in postback event or PreRender event.
| > | > > > >
| > | > > > > In addition, for your detaile scenario, I've just built a very
| > | simple
| > | > > demo
| > | > > > > control which have three dropdownlists and The "Top" one will
| > | display
| > | > > > > first(other twos invisible) and according to the top one's
| > | selection,
| > | > > the
| > | > > > > "Mid" dropdownlist will be pouplated and the same when the
| "mid"'s
| > | > > > > selection changed......
| > | > > > >
| > | > > > > Here's the control's code for your reference:
| > | > > > >
| > | > > > > =========================
| > | > > > > [DefaultProperty("Text"),
| > | > > > > ToolboxData("<{0}:MultiListControl
| > | > > runat=server></{0}:MultiListControl>")]
| > | > > > > public class MultiListControl :
| > | System.Web.UI.WebControls.WebControl,
| > | > > > > INamingContainer
| > | > > > > {
| > | > > > > private string text;
| > | > > > >
| > | > > > > private DropDownList lstTop;
| > | > > > > private DropDownList lstMid;
| > | > > > > private DropDownList lstBot;
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > protected bool MidVisible
| > | > > > > {
| > | > > > > get{
| > | > > > > if(ViewState["MID_VISIBLE"] == null)
| > | > > > > {
| > | > > > > return false;
| > | > > > > }
| > | > > > >
| > | > > > > return (bool)ViewState["MID_VISIBLE"];
| > | > > > > }
| > | > > > >
| > | > > > > set{
| > | > > > > TrackViewState();
| > | > > > > ViewState["MID_VISIBLE"] = value;
| > | > > > > }
| > | > > > > }
| > | > > > >
| > | > > > > protected bool BotVisible
| > | > > > > {
| > | > > > > get
| > | > > > > {
| > | > > > > if(ViewState["BOT_VISIBLE"] == null)
| > | > > > > {
| > | > > > > return false;
| > | > > > > }
| > | > > > >
| > | > > > > return (bool)ViewState["BOT_VISIBLE"];
| > | > > > > }
| > | > > > >
| > | > > > > set
| > | > > > > {
| > | > > > > TrackViewState();
| > | > > > > ViewState["BOT_VISIBLE"] = value;
| > | > > > > }
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > [Bindable(true),
| > | > > > > Category("Appearance"),
| > | > > > > DefaultValue("")]
| > | > > > > public string Text
| > | > > > > {
| > | > > > > get
| > | > > > > {
| > | > > > > return text;
| > | > > > > }
| > | > > > >
| > | > > > > set
| > | > > > > {
| > | > > > > text = value;
| > | > > > > }
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > protected override void CreateChildControls()
| > | > > > > {
| > | > > > > Controls.Clear();
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"
| > | > > > > <table width='100%'>
| > | > > > > <tr><td>
| > | > > > > "));
| > | > > > >
| > | > > > > lstTop = new DropDownList();
| > | > > > > lstTop.ID = "lstTop";
| > | > > > >
| > | > > > > lstTop.Items.Add("----------");
| > | > > > > lstTop.Items.Add("Top_Item_1");
| > | > > > > lstTop.Items.Add("Top_Item_2");
| > | > > > > lstTop.Items.Add("Top_Item_3");
| > | > > > > lstTop.Items.Add("Top_Item_4");
| > | > > > >
| > | > > > > Controls.Add(lstTop);
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"<br/>"
| > | > > > > ));
| > | > > > >
| > | > > > > lstMid = new DropDownList();
| > | > > > > lstMid.ID = "lstMid";
| > | > > > >
| > | > > > > Controls.Add(lstMid);
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"<br/>"
| > | > > > > ));
| > | > > > >
| > | > > > >
| > | > > > > lstBot = new DropDownList();
| > | > > > > lstBot.ID = "lstBot";
| > | > > > >
| > | > > > > Controls.Add(lstBot);
| > | > > > >
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"
| > | > > > > </td></tr>
| > | > > > > </table>
| > | > > > > "
| > | > > > > ));
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > lstTop.SelectedIndexChanged +=new
| > | > > EventHandler(lst_SelectedIndexChanged);
| > | > > > > lstMid.SelectedIndexChanged +=new
| > | > > EventHandler(lst_SelectedIndexChanged);
| > | > > > > lstBot.SelectedIndexChanged +=new
| > | > > EventHandler(lst_SelectedIndexChanged);
| > | > > > >
| > | > > > > lstTop.AutoPostBack = lstMid.AutoPostBack =
lstBot.AutoPostBack
| =
| > | > true;
| > | > > > >
| > | > > > >
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > protected override void OnPreRender(EventArgs e)
| > | > > > > {
| > | > > > > base.OnPreRender (e);
| > | > > > >
| > | > > > > lstMid.Visible = MidVisible;
| > | > > > > lstBot.Visible = BotVisible;
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > private void lst_SelectedIndexChanged(object sender,
| > | System.EventArgs
| > | > e)
| > | > > > > {
| > | > > > >
| > | > > > > DropDownList lst = sender as DropDownList;
| > | > > > >
| > | > > > > switch(lst.ID)
| > | > > > > {
| > | > > > > case "lstTop":
| > | > > > >
| > | > > > > if(lst.SelectedIndex != 0)
| > | > > > > {
| > | > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > | > > > > lstMid.DataTextField = "Text";
| > | > > > > lstMid.DataValueField= "Value";
| > | > > > > lstMid.DataBind();
| > | > > > >
| > | > > > > MidVisible = true;
| > | > > > > }
| > | > > > > else
| > | > > > > {
| > | > > > > MidVisible = BotVisible = false;
| > | > > > > }
| > | > > > >
| > | > > > > break;
| > | > > > > case "lstMid":
| > | > > > >
| > | > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > | > > > > lstBot.DataTextField = "Text";
| > | > > > > lstBot.DataValueField= "Value";
| > | > > > > lstBot.DataBind();
| > | > > > >
| > | > > > > MidVisible = BotVisible = true;
| > | > > > >
| > | > > > > break;
| > | > > > > case "lstBot":
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > break;
| > | > > > > }
| > | > > > >
| > | > > > > Page.Response.Write("<br>" + lst.ID +
"_selectedindexchanged!" +
| > | > > > > lst.EnableViewState);
| > | > > > > }
| > | > > > >
| > | > > > > #region --Helper functions---
| > | > > > >
| > | > > > > public ListItemCollection GetSubItems(string parent)
| > | > > > > {
| > | > > > > ListItemCollection items = new ListItemCollection();
| > | > > > > int count = parent.Length;
| > | > > > >
| > | > > > > for(int i=0;i<count;++i)
| > | > > > > {
| > | > > > > items.Add(parent + "_Item_" + i);
| > | > > > > }
| > | > > > >
| > | > > > > return items;
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > #endregion
| > | > > > > }
| > | > > > >
| > | > > > > ========================
| > | > > > > Hope helps. Thanks,
| > | > > > >
| > | > > > > Steven Cheng
| > | > > > > Microsoft Online Support
| > | > > > >
| > | > > > > Get Secure! www.microsoft.com/security
| > | > > > > (This posting is provided "AS IS", with no warranties, and
| confers
| > | no
| > | > > > > rights.)
| > | > > > >
| > | > > > >
| > | > > > > --------------------
| > | > > > > | From: "TS" <[email protected]>
| > | > > > > | References: <[email protected]>
| > | > > > > | Subject: Re: explanation of when need to repopulate control
| > | > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > | > > > > | Lines: 39
| > | > > > > | X-Priority: 3
| > | > > > > | X-MSMail-Priority: Normal
| > | > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > > > > | Message-ID: <[email protected]>
| > | > > > > | Newsgroups:
| > | > > > >
| > | > > >
| > | > >
| > | >
| > |
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > | > > > > framework.aspnet.buildingcontrols
| > | > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | > > > > | Path:
| > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > > > > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > | > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > | > > > > | X-Tomcat-NG:
| > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > > > > |
| > | > > > > | sorry, heres the scenario i'm trying to accomplish:
| > | > > > > | I have a composite control that contains 4 drop down lists.
| When
| > | the
| > | > > > page
| > | > > > > | loads initially, i want the first drop down filled and the
| rest
| > | > > > invisible.
| > | > > > > | When you select an item in this ddl, it posts back to the
| server
| > | and
| > | > > > based
| > | > > > > | on its value, it populates its immediate child's drop down
| list.
| > | So
| > | > > now
| > | > > > > the
| > | > > > > | top ddl has a value selected and the 2nd one just has its
| items
| > | > > > populated.
| > | > > > > | Then when the 2nd drop down list gets selected, it posts to
| the
| > | > server
| > | > > > and
| > | > > > > | its value is used to populate(filter) the items for the 3rd
| drop
| > | > down
| > | > > > > | list...and so on for each drop down list.
| > | > > > > |
| > | > > > > | Please tell me what i need to do to handle post back data
and
| > | > maintain
| > | > > > > state
| > | > > > > | from one postback to another while keeping the drop
downlists
| > | filled
| > | > > and
| > | > > > > | their values persisted.
| > | > > > > |
| > | > > > > | thank you again!
| > | > > > > |
| > | > > > > |
| > | > > > > | | > | > > > > | > I have a quesiton:
| > | > > > > | > if i have a composite control and on its intial page
| loading,
| > i
| > | > fill
| > | > > > my
| > | > > > > | (sub
| > | > > > > | > control) drop down list's items collection from the
database
| > and
| > | > > > return.
| > | > > > > | > When the user hits a button to cause postback, the control
| is
| > | > going
| > | > > to
| > | > > > > get
| > | > > > > | > initialized, then does its items collection that i filled
on
| > the
| > | > > > initial
| > | > > > > | > page request get repopulated from viewstate? And on top of
| > that,
| > | > if
| > | > > > so,
| > | > > > > | does
| > | > > > > | > the list item that person selected in the drop down list
| again
| > | set
| > | > > > > itself
| > | > > > > | as
| > | > > > > | > the selected item in the list?
| > | > > > > | >
| > | > > > > | > OR do i have to re-load the items on every page request
and
| > then
| > | > > > > populate
| > | > > > > | > its value some other way???
| > | > > > > | >
| > | > > > > | > thanks a bunch
| > | > > > > | >
| > | > > > > | >
| > | > > > > |
| > | > > > > |
| > | > > > > |
| > | > > > >
| > | > > >
| > | > > >
| > | > >
| > | > >
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|
 
T

TS

Well you were right that it had something to do with the custom control. The
datalist was trying to load itself during page load. i put the code in Init,
and it worked.

thanks steven

Steven Cheng said:
Thanks for your followup TS.

So can I say that currently your custom webcontrol(not template list
control) can correctly be added both statically and dynamically in the
normal DataList or Repeater controls (asp.net buildin ) , but have some
problem for postback events when added in your custom list control?

If so, we should keep focus on the custom datalist control. Has it any
problems when we nest some asp.net buildin controls in it? Would you try
making a simplified version of your custom datalist control so that we can
have a view to see whether there is anything wrong in it. Also, it'll be
helpful you also provide the complete code that you dynamically add control
into the datalist (through reflection).

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Fri, 5 Aug 2005 17:19:23 -0500
| Lines: 1298
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4003
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| I have a new problem now. I have figured out that the cause is the same
| reason. If its in the custom DataList, it doesn't work, else it does work.
|
| The scenario:
| After the initial page load, you enter data into controls and hit submit
| button, the process is as follows:
| Page_Load
| DataList's OnLoad
| Composite Control's OnLoad
| Submit button's OnClick - At this point, the controls in the composite
| control have no listitems and no selectedValue properties.
|
| I have statically added the composite control onto the same page as the
| dynamic one, so here is the process in this scenario:
| Page_Load
| Composite Control's OnLoad (The one whose parent is Page)
| DataList's OnLoad
| Composite Control's OnLoad (The one whose parent is the Custom DataList)
| Submit button's OnClick - At this point, the controls in the statically
| declared composite control have listitems and have values for
selectedValue
| properties.
|
| So the same control at the same time - the one outside the custom Datalist
| has its controls' state set up correctly, the ones inside does not.
|
| So the same reason is at play here. Maybe since i am dynamically creating
| the class using reflection (Assembly.CreateInstance()) that has something
to
| do with it?
|
| Please help mr. Cheng.
|
| Thank you very much!
|
| TS
|
|
|
| | > Hi TS,
| >
| > First, I'm glad that you've got your composite control work, all the
| > dropdownlist's postback events can fire correctly,yes?
| >
| > As for the new problem you encountered when adding your composite
control
| > into DataList's item, is the DataList the asp.net's buildin DataList
| > control? And since you mentioned that you dynamically add your control
| > into it, how do you dynamically add your custom control? Will there
occur
| > problem if you statically add your control into DataList?
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "TS" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <unRs#[email protected]>
| > <[email protected]>
| > | Subject: Re: explanation of when need to repopulate control
| > | Date: Wed, 3 Aug 2005 19:07:16 -0500
| > | Lines: 1153
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | Well Steve, I am almost done. My control works well, except its not in
| the
| > | framework i just mentioned. Adding my control dynamically to the
| > datalist's
| > | item may be the root of the cause. i've made sure all custom controls
| > | implmenet INamingContainer & I think all controls have their id's set,
| so
| > | what else can i do?
| > |
| > | thanks a bunch
| > |
| > | | > | > I have figured the cause of the problem, sort of. My main control
was
| > | being
| > | > loaded dynamically during a custom data list control's ItemDataBound
| > | event,
| > | > and then added to the e.item.controls collection. Once I removed it
| from
| > | > here, the correct event was called in my control. the problem is i
| need
| > to
| > | > keep it where it is because of the way the page works.
| > | >
| > | > I tried to add INamingContainer to the custom Datalist, but that
| didn't
| > | > help. Any ideas what could make this happen?
| > | >
| > | > thanks so much, i know i'm being a pain, but i'm stuck!
| > | >
| > | > This is the custom DataLists' event:
| > | > protected override void OnItemDataBound(DataListItemEventArgs e)
| > | >
| > | > {
| > | >
| > | > base.OnItemDataBound(e);
| > | >
| > | > Parameter parameter = (Parameter)e.Item.DataItem;
| > | >
| > | > try
| > | >
| > | > {
| > | >
| > | > Control control;
| > | >
| > | > if(parameter.Type == ParameterType.Control)
| > | >
| > | > control = this.Page.LoadControl(parameter.ControlPath);
| > | >
| > | > else
| > | >
| > | > {
| > | >
| > | > Assembly assembly = parameter.Assembly;
| > | >
| > | > if(assembly == null)
| > | >
| > | > {
| > | >
| > | > // The control didn't declare its own assembly, so use the report's
| > | > ControlsAssembly
| > | >
| > | > assembly = this.ControlsAssembly;
| > | >
| > | > // Ther report's ControlsAssembly is null, so use current page's
| > assembly
| > | >
| > | > if(assembly == null)
| > | >
| > | > assembly = this.Page.GetType().BaseType.Assembly;
| > | >
| > | > }
| > | >
| > | >
| > | > control = (Control)
| assembly.CreateInstance(parameter.ControlTypeName);
| > | >
| > | > }
| > | >
| > | > control.ID = parameter.Name;
| > | >
| > | > // Set up all the properties of this control from the
| > parameter.properties
| > | >
| > | > foreach(DictionaryEntry de in parameter.Properties)
| > | >
| > | > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| > | >
| > | >
| > | > e.Item.Controls.Add(control);
| > | >
| > | > }
| > | >
| > | > catch (Exception ex)
| > | >
| > | > {
| > | >
| > | > throw new ApplicationException("Unable to render criteria. Reason:
" +
| > | > ex.Message, ex);
| > | >
| > | > }
| > | >
| > | > }
| > | >
| > | > | > | > > In testing, i removed the main parent dropdown and only left the 2
| > below
| > | > it.
| > | > > this time, the same scenario happened...when the child dropdown
list
| > | > > autopostsback, it's immediate parent's selectedindexchanged event
| > fires!
| > | I
| > | > 'm
| > | > > starting to pull my hair out now...I"m stuck!
| > | > >
| > | > > please help superman
| > | > >
| > | > > | > | > > > Another problem:
| > | > > >
| > | > > > while i'm waiting on your remark to my last post, i removed the
| sub
| > | > > > composite controls from my composite control so that there is
only
| > | drop
| > | > > down
| > | > > > lists on it. During CreateChildcontrols, i load the main drop
down
| > | using
| > | > > > databind. When the page is sent to browser for the first time, i
| > have
| > | my
| > | > > > main drop down filled. I then select an item and its
| > | > SelectedIndexChanged
| > | > > > fires and populates the send drop down list. Then when i select
an
| > | item
| > | > > from
| > | > > > it, it posts back, and the event that gets called is the
| main(first)
| > | > > > dropdown list's SelectedIndexChanged event, which then
| re-populates
| > | the
| > | > > > second drop down list, then the control returns to the browser
| (The
| > | > > > SelectedIndexChanged event never fired for the 2nd dropdown's
| > changed
| > | > > > event.???
| > | > > >
| > | > > > thanks again
| > | > > >
| > | > > > using System;
| > | > > >
| > | > > > using System.Collections.Specialized;
| > | > > >
| > | > > > using System.Web.UI;
| > | > > >
| > | > > > using System.Web.UI.WebControls;
| > | > > >
| > | > > > using System.Text;
| > | > > >
| > | > > > using OperationsTeams.Business;
| > | > > >
| > | > > > using OperationsTeams.Data;
| > | > > >
| > | > > > using OperationsTeams.Reporting;
| > | > > >
| > | > > > using OperationsTeams.Reporting.WebControls;
| > | > > >
| > | > > > namespace OperationsTeams.Web.ReportControls
| > | > > >
| > | > > > {
| > | > > >
| > | > > > /// <summary>
| > | > > >
| > | > > > /// Summary description for FiscalAgentHierarchy.
| > | > > >
| > | > > > /// </summary>
| > | > > >
| > | > > > public class FiscalAgentHierarchy : WebControl,
| > | IReportParameterControl,
| > | > > > INamingContainer
| > | > > >
| > | > > > {
| > | > > >
| > | > > > 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
| > | > > >
| > | > > > protected override void OnLoad(EventArgs e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > base.OnLoad (e);
| > | > > >
| > | > > >
| > | > > > // The last state of controls from viewstate is now loaded
(Before
| > the
| > | > > > client data is processed)
| > | > > >
| > | > > > }
| > | > > >
| > | > > >
| > | > > > protected override void OnPreRender(EventArgs e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > base.OnPreRender (e);
| > | > > >
| > | > > > // The controls now have the client values from the the last
| > postback
| > | > > >
| > | > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > | > > >
| > | > > > // ddlProviders.Visible = ProviderVisible;
| > | > > >
| > | > > > // ddlSites.Visible = SiteVisible;
| > | > > >
| > | > > > // ddlClasses.Visible = ClassVisible;
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > > >
| > | > > > // ddlSites.Visible = true;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > 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 ddlFundingSource_SelectedIndexChanged(object
sender,
| > | > > EventArgs
| > | > > > e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > LoadSites();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void ddlProviders_SelectedIndexChanged(object sender,
| > | EventArgs
| > | > e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > LoadSites();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void ddlSites_SelectedIndexChanged(object sender,
| EventArgs
| > e)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > LoadClasses();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > #endregion
| > | > > >
| > | > > > protected override void CreateChildControls()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > this.ddlFundingSource = new DropDownList();
| > | > > >
| > | > > > this.ddlProviders = new DropDownList();
| > | > > >
| > | > > > this.ddlSites = new DropDownList();
| > | > > >
| > | > > > this.ddlClasses = new DropDownList();
| > | > > >
| > | > > > ddlFundingSource.ID = FundingSourceControlId;
| > | > > >
| > | > > > ddlProviders.ID = ProvidersControlId;
| > | > > >
| > | > > > ddlSites.ID = SitesControlId;
| > | > > >
| > | > > > ddlClasses.ID = ClassesControlId;
| > | > > >
| > | > > >
| > | > > > LoadProviders();
| > | > > >
| > | > > > // 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( said:
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > > this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>"));
| > | > > >
| > | > > > // this.Controls.Add(fasFiscalAgent);
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > > Source</td><td>"));
| > | > > >
| > | > > > this.Controls.Add(ddlFundingSource);
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
| > | > >
| > | >
| > |
| >
|
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > > );
| > | > > >
| > | > > > this.Controls.Add(ddlProviders);
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
| > | >
| >
this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Sites</td><td>"));
| > | > > >
| > | > > > this.Controls.Add(ddlSites);
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > >
| > | > >
| > | >
| > |
| >
|
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > > this.Controls.Add(ddlClasses);
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > > // end containing table
| > | > > >
| > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > > >
| > | > > > ddlFundingSource.SelectedIndexChanged += new
| > | > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > | > > >
| > | > > > ddlProviders.SelectedIndexChanged += new
| > | > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > | > > >
| > | > > > ddlSites.SelectedIndexChanged += new
| > | > > > EventHandler(ddlSites_SelectedIndexChanged);
| > | > > >
| > | > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > | > > > ddlSites.AutoPostBack = true;
| > | > > >
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadFundingSource()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > int fiscalAgentId =
1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > | > > >
| > | > > >
| > | > > > if(fiscalAgentId != int.MinValue)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > FundingSourceVisible = 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
| > | > > >
| > | > > > {
| > | > > >
| > | > > > FundingSourceVisible = false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadProviders()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > int fiscalAgentId = 1;//fasFiscalAgent.SelectedFiscalAgentId;
| > | > > >
| > | > > > if(fiscalAgentId != int.MinValue)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > > >
| > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > > >
| > | > > >
| > | > > >
| > | > > > ProviderVisible = true;
| > | > > >
| > | > > > // are these dates correct???????????????????????????
| > | > > >
| > | > > > ddlProviders.DataSource =
FiscalAgentProvider.Find(fiscalAgentId,
| > new
| > | > > > DateTime(2005,7,1), new
| > | > > >
| > |
DateTime(2006,6,30));//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();
| > | > > >
| > | > > > ProviderVisible = false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > // LoadSites();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadSites()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ddlProviders.SelectedValue != string.Empty)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > // Load the Site search parameters.
| > | > > >
| > | > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > | > > >
| > | > > > siteFindArgs.FiscalAgentId=1;
| > | > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > > >
| > | > > > SiteVisible = 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();
| > | > > >
| > | > > > SiteVisible = false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > // LoadClasses();
| > | > > >
| > | > > > }
| > | > > >
| > | > > > private void LoadClasses()
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ddlSites.SelectedValue != string.Empty)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| > | AdultEdClassFindArgs();
| > | > > >
| > | > > > // adultEdClassFindArgs.FiscalAgentId =
| > | > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > > >
| > | > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > | > > > rysReportingYearSelector.ReportingYearStartDate;
| > | > > >
| > | > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > | > > > rysReportingYearSelector.ReportingYearEndDate;
| > | > > >
| > | > > > // adultEdClassFindArgs.ProviderName =
ddlProviders.SelectedValue;
| > | > > >
| > | > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > | > > >
| > | > > >
| > | > > > ClassVisible = true;
| > | > > >
| > | > > > ddlClasses.DataSource = AdultEdClass.Find(adultEdClassFindArgs);
| > | > > >
| > | > > > ddlClasses.DataTextField = "Name";
| > | > > >
| > | > > > ddlClasses.DataValueField = "ClassId";
| > | > > >
| > | > > > ddlClasses.DataBind();
| > | > > >
| > | > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
| > string.Empty));
| > | > > >
| > | > > > }
| > | > > >
| > | > > > else
| > | > > >
| > | > > > {
| > | > > >
| > | > > > ddlClasses.Items.Clear();
| > | > > >
| > | > > > ClassVisible = 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
| > | > > >
| > | > > > protected bool FundingSourceVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["FundingSourceVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["FundingSourceVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["FundingSourceVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > protected bool ProviderVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["ProviderVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["ProviderVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["ProviderVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > protected bool SiteVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["SiteVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["SiteVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["SiteVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > protected bool ClassVisible
| > | > > >
| > | > > > {
| > | > > >
| > | > > > get
| > | > > >
| > | > > > {
| > | > > >
| > | > > > if(ViewState["ClassVisible"] == null)
| > | > > >
| > | > > > {
| > | > > >
| > | > > > return false;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > return (bool)ViewState["ClassVisible"];
| > | > > >
| > | > > > }
| > | > > >
| > | > > > set
| > | > > >
| > | > > > {
| > | > > >
| > | > > > TrackViewState();
| > | > > >
| > | > > > ViewState["ClassVisible"] = value;
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > > #endregion
| > | > > >
| > | > > > #region Private Member Variables
| > | > > >
| > | > > > 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
| > | > > >
| > | > > > }
| > | > > >
| > | > > > }
| > | > > >
| > | > > >
| message
| > | > > > | > | > > > > Hi TS,
| > | > > > >
| > | > > > > See you again :), seems you're rushing in a asp.net project
| these
| > | > days?
| > | > > > > For the question you mentioned in this post, here are some of
my
| > | > > > > understanding and suggestions:
| > | > > > >
| > | > > > > 1. ASP.NET controls derived from Control will automatically
| > maintain
| > | > its
| > | > > > > ViewStates according to the asp.net web page's events
sequence.
| So
| > | for
| > | > > > > composite control, those nested sub Controls' status
(properties
| > | which
| > | > > be
| > | > > > > persistd in Viewsstate ) will be store and retrieve
| automatically.
| > | > > > >
| > | > > > > 2. However, there're some thing we need to care when building
| > | > composite
| > | > > > > control:
| > | > > > > #remember to implement INamingContainer for controls which
will
| > have
| > | > > > nested
| > | > > > > sub controls. Otherwise, even handler mapping, ViewState
loading
| > | will
| > | > > > occur
| > | > > > > unexpectedly.
| > | > > > >
| > | > > > > #Do remember to assign a explicit ID for each sub
controls(same
| > | reason
| > | > > as
| > | > > > > #1). Also, please always try best to add subcontrols in the
| > | > > > > "CreateChildControls" method(just create control hierarchy)
and
| > put
| > | > > > > manipulating code in postback event or PreRender event.
| > | > > > >
| > | > > > > In addition, for your detaile scenario, I've just built a very
| > | simple
| > | > > demo
| > | > > > > control which have three dropdownlists and The "Top" one will
| > | display
| > | > > > > first(other twos invisible) and according to the top one's
| > | selection,
| > | > > the
| > | > > > > "Mid" dropdownlist will be pouplated and the same when the
| "mid"'s
| > | > > > > selection changed......
| > | > > > >
| > | > > > > Here's the control's code for your reference:
| > | > > > >
| > | > > > > =========================
| > | > > > > [DefaultProperty("Text"),
| > | > > > > ToolboxData("<{0}:MultiListControl
| > | > > runat=server></{0}:MultiListControl>")]
| > | > > > > public class MultiListControl :
| > | System.Web.UI.WebControls.WebControl,
| > | > > > > INamingContainer
| > | > > > > {
| > | > > > > private string text;
| > | > > > >
| > | > > > > private DropDownList lstTop;
| > | > > > > private DropDownList lstMid;
| > | > > > > private DropDownList lstBot;
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > protected bool MidVisible
| > | > > > > {
| > | > > > > get{
| > | > > > > if(ViewState["MID_VISIBLE"] == null)
| > | > > > > {
| > | > > > > return false;
| > | > > > > }
| > | > > > >
| > | > > > > return (bool)ViewState["MID_VISIBLE"];
| > | > > > > }
| > | > > > >
| > | > > > > set{
| > | > > > > TrackViewState();
| > | > > > > ViewState["MID_VISIBLE"] = value;
| > | > > > > }
| > | > > > > }
| > | > > > >
| > | > > > > protected bool BotVisible
| > | > > > > {
| > | > > > > get
| > | > > > > {
| > | > > > > if(ViewState["BOT_VISIBLE"] == null)
| > | > > > > {
| > | > > > > return false;
| > | > > > > }
| > | > > > >
| > | > > > > return (bool)ViewState["BOT_VISIBLE"];
| > | > > > > }
| > | > > > >
| > | > > > > set
| > | > > > > {
| > | > > > > TrackViewState();
| > | > > > > ViewState["BOT_VISIBLE"] = value;
| > | > > > > }
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > [Bindable(true),
| > | > > > > Category("Appearance"),
| > | > > > > DefaultValue("")]
| > | > > > > public string Text
| > | > > > > {
| > | > > > > get
| > | > > > > {
| > | > > > > return text;
| > | > > > > }
| > | > > > >
| > | > > > > set
| > | > > > > {
| > | > > > > text = value;
| > | > > > > }
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > protected override void CreateChildControls()
| > | > > > > {
| > | > > > > Controls.Clear();
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"
| > | > > > > <table width='100%'>
| > | > > > > <tr><td>
| > | > > > > "));
| > | > > > >
| > | > > > > lstTop = new DropDownList();
| > | > > > > lstTop.ID = "lstTop";
| > | > > > >
| > | > > > > lstTop.Items.Add("----------");
| > | > > > > lstTop.Items.Add("Top_Item_1");
| > | > > > > lstTop.Items.Add("Top_Item_2");
| > | > > > > lstTop.Items.Add("Top_Item_3");
| > | > > > > lstTop.Items.Add("Top_Item_4");
| > | > > > >
| > | > > > > Controls.Add(lstTop);
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"<br/>"
| > | > > > > ));
| > | > > > >
| > | > > > > lstMid = new DropDownList();
| > | > > > > lstMid.ID = "lstMid";
| > | > > > >
| > | > > > > Controls.Add(lstMid);
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"<br/>"
| > | > > > > ));
| > | > > > >
| > | > > > >
| > | > > > > lstBot = new DropDownList();
| > | > > > > lstBot.ID = "lstBot";
| > | > > > >
| > | > > > > Controls.Add(lstBot);
| > | > > > >
| > | > > > >
| > | > > > > Controls.Add(
| > | > > > > new LiteralControl(
| > | > > > > @"
| > | > > > > </td></tr>
| > | > > > > </table>
| > | > > > > "
| > | > > > > ));
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > lstTop.SelectedIndexChanged +=new
| > | > > EventHandler(lst_SelectedIndexChanged);
| > | > > > > lstMid.SelectedIndexChanged +=new
| > | > > EventHandler(lst_SelectedIndexChanged);
| > | > > > > lstBot.SelectedIndexChanged +=new
| > | > > EventHandler(lst_SelectedIndexChanged);
| > | > > > >
| > | > > > > lstTop.AutoPostBack = lstMid.AutoPostBack =
lstBot.AutoPostBack
| =
| > | > true;
| > | > > > >
| > | > > > >
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > protected override void OnPreRender(EventArgs e)
| > | > > > > {
| > | > > > > base.OnPreRender (e);
| > | > > > >
| > | > > > > lstMid.Visible = MidVisible;
| > | > > > > lstBot.Visible = BotVisible;
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > private void lst_SelectedIndexChanged(object sender,
| > | System.EventArgs
| > | > e)
| > | > > > > {
| > | > > > >
| > | > > > > DropDownList lst = sender as DropDownList;
| > | > > > >
| > | > > > > switch(lst.ID)
| > | > > > > {
| > | > > > > case "lstTop":
| > | > > > >
| > | > > > > if(lst.SelectedIndex != 0)
| > | > > > > {
| > | > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > | > > > > lstMid.DataTextField = "Text";
| > | > > > > lstMid.DataValueField= "Value";
| > | > > > > lstMid.DataBind();
| > | > > > >
| > | > > > > MidVisible = true;
| > | > > > > }
| > | > > > > else
| > | > > > > {
| > | > > > > MidVisible = BotVisible = false;
| > | > > > > }
| > | > > > >
| > | > > > > break;
| > | > > > > case "lstMid":
| > | > > > >
| > | > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > | > > > > lstBot.DataTextField = "Text";
| > | > > > > lstBot.DataValueField= "Value";
| > | > > > > lstBot.DataBind();
| > | > > > >
| > | > > > > MidVisible = BotVisible = true;
| > | > > > >
| > | > > > > break;
| > | > > > > case "lstBot":
| > | > > > >
| > | > > > >
| > | > > > >
| > | > > > > break;
| > | > > > > }
| > | > > > >
| > | > > > > Page.Response.Write("<br>" + lst.ID +
"_selectedindexchanged!" +
| > | > > > > lst.EnableViewState);
| > | > > > > }
| > | > > > >
| > | > > > > #region --Helper functions---
| > | > > > >
| > | > > > > public ListItemCollection GetSubItems(string parent)
| > | > > > > {
| > | > > > > ListItemCollection items = new ListItemCollection();
| > | > > > > int count = parent.Length;
| > | > > > >
| > | > > > > for(int i=0;i<count;++i)
| > | > > > > {
| > | > > > > items.Add(parent + "_Item_" + i);
| > | > > > > }
| > | > > > >
| > | > > > > return items;
| > | > > > > }
| > | > > > >
| > | > > > >
| > | > > > > #endregion
| > | > > > > }
| > | > > > >
| > | > > > > ========================
| > | > > > > Hope helps. Thanks,
| > | > > > >
| > | > > > > Steven Cheng
| > | > > > > Microsoft Online Support
| > | > > > >
| > | > > > > Get Secure! www.microsoft.com/security
| > | > > > > (This posting is provided "AS IS", with no warranties, and
| confers
| > | no
| > | > > > > rights.)
| > | > > > >
| > | > > > >
| > | > > > > --------------------
| > | > > > > | From: "TS" <[email protected]>
| > | > > > > | References: <[email protected]>
| > | > > > > | Subject: Re: explanation of when need to repopulate control
| > | > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > | > > > > | Lines: 39
| > | > > > > | X-Priority: 3
| > | > > > > | X-MSMail-Priority: Normal
| > | > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > > > > | Message-ID: <[email protected]>
| > | > > > > | Newsgroups:
| > | > > > >
| > | > > >
| > | > >
| > | >
| > |
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > | > > > > framework.aspnet.buildingcontrols
| > | > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | > > > > | Path:
| > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > > > > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > | > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > | > > > > | X-Tomcat-NG:
| > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > > > > |
| > | > > > > | sorry, heres the scenario i'm trying to accomplish:
| > | > > > > | I have a composite control that contains 4 drop down lists.
| When
| > | the
| > | > > > page
| > | > > > > | loads initially, i want the first drop down filled and the
| rest
| > | > > > invisible.
| > | > > > > | When you select an item in this ddl, it posts back to the
| server
| > | and
| > | > > > based
| > | > > > > | on its value, it populates its immediate child's drop down
| list.
| > | So
| > | > > now
| > | > > > > the
| > | > > > > | top ddl has a value selected and the 2nd one just has its
| items
| > | > > > populated.
| > | > > > > | Then when the 2nd drop down list gets selected, it posts to
| the
| > | > server
| > | > > > and
| > | > > > > | its value is used to populate(filter) the items for the 3rd
| drop
| > | > down
| > | > > > > | list...and so on for each drop down list.
| > | > > > > |
| > | > > > > | Please tell me what i need to do to handle post back data
and
| > | > maintain
| > | > > > > state
| > | > > > > | from one postback to another while keeping the drop
downlists
| > | filled
| > | > > and
| > | > > > > | their values persisted.
| > | > > > > |
| > | > > > > | thank you again!
| > | > > > > |
| > | > > > > |
| > | > > > > | | > | > > > > | > I have a quesiton:
| > | > > > > | > if i have a composite control and on its intial page
| loading,
| > i
| > | > fill
| > | > > > my
| > | > > > > | (sub
| > | > > > > | > control) drop down list's items collection from the
database
| > and
| > | > > > return.
| > | > > > > | > When the user hits a button to cause postback, the control
| is
| > | > going
| > | > > to
| > | > > > > get
| > | > > > > | > initialized, then does its items collection that i filled
on
| > the
| > | > > > initial
| > | > > > > | > page request get repopulated from viewstate? And on top of
| > that,
| > | > if
| > | > > > so,
| > | > > > > | does
| > | > > > > | > the list item that person selected in the drop down list
| again
| > | set
| > | > > > > itself
| > | > > > > | as
| > | > > > > | > the selected item in the list?
| > | > > > > | >
| > | > > > > | > OR do i have to re-load the items on every page request
and
| > then
| > | > > > > populate
| > | > > > > | > its value some other way???
| > | > > > > | >
| > | > > > > | > thanks a bunch
| > | > > > > | >
| > | > > > > | >
| > | > > > > |
| > | > > > > |
| > | > > > > |
| > | > > > >
| > | > > >
| > | > > >
| > | > >
| > | > >
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|
 
S

Steven Cheng[MSFT]

You're welcome TS.

Glad that you've overcome the problem.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Mon, 8 Aug 2005 12:50:32 -0500
| Lines: 1445
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4014
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well you were right that it had something to do with the custom control.
The
| datalist was trying to load itself during page load. i put the code in
Init,
| and it worked.
|
| thanks steven
|
| | > Thanks for your followup TS.
| >
| > So can I say that currently your custom webcontrol(not template list
| > control) can correctly be added both statically and dynamically in the
| > normal DataList or Repeater controls (asp.net buildin ) , but have some
| > problem for postback events when added in your custom list control?
| >
| > If so, we should keep focus on the custom datalist control. Has it any
| > problems when we nest some asp.net buildin controls in it? Would you try
| > making a simplified version of your custom datalist control so that we
can
| > have a view to see whether there is anything wrong in it. Also, it'll be
| > helpful you also provide the complete code that you dynamically add
| control
| > into the datalist (through reflection).
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "TS" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <unRs#[email protected]>
| > <[email protected]>
| > <#[email protected]>
| > <[email protected]>
| > | Subject: Re: explanation of when need to repopulate control
| > | Date: Fri, 5 Aug 2005 17:19:23 -0500
| > | Lines: 1298
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:4003
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | I have a new problem now. I have figured out that the cause is the
same
| > | reason. If its in the custom DataList, it doesn't work, else it does
| work.
| > |
| > | The scenario:
| > | After the initial page load, you enter data into controls and hit
submit
| > | button, the process is as follows:
| > | Page_Load
| > | DataList's OnLoad
| > | Composite Control's OnLoad
| > | Submit button's OnClick - At this point, the controls in the composite
| > | control have no listitems and no selectedValue properties.
| > |
| > | I have statically added the composite control onto the same page as
the
| > | dynamic one, so here is the process in this scenario:
| > | Page_Load
| > | Composite Control's OnLoad (The one whose parent is Page)
| > | DataList's OnLoad
| > | Composite Control's OnLoad (The one whose parent is the Custom
DataList)
| > | Submit button's OnClick - At this point, the controls in the
statically
| > | declared composite control have listitems and have values for
| > selectedValue
| > | properties.
| > |
| > | So the same control at the same time - the one outside the custom
| Datalist
| > | has its controls' state set up correctly, the ones inside does not.
| > |
| > | So the same reason is at play here. Maybe since i am dynamically
| creating
| > | the class using reflection (Assembly.CreateInstance()) that has
| something
| > to
| > | do with it?
| > |
| > | Please help mr. Cheng.
| > |
| > | Thank you very much!
| > |
| > | TS
| > |
| > |
| > |
| > | | > | > Hi TS,
| > | >
| > | > First, I'm glad that you've got your composite control work, all the
| > | > dropdownlist's postback events can fire correctly,yes?
| > | >
| > | > As for the new problem you encountered when adding your composite
| > control
| > | > into DataList's item, is the DataList the asp.net's buildin DataList
| > | > control? And since you mentioned that you dynamically add your
| control
| > | > into it, how do you dynamically add your custom control? Will there
| > occur
| > | > problem if you statically add your control into DataList?
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | > --------------------
| > | > | From: "TS" <[email protected]>
| > | > | References: <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <unRs#[email protected]>
| > | > <[email protected]>
| > | > | Subject: Re: explanation of when need to repopulate control
| > | > | Date: Wed, 3 Aug 2005 19:07:16 -0500
| > | > | Lines: 1153
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | > | Path:
| TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| > | > | X-Tomcat-NG:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > |
| > | > | Well Steve, I am almost done. My control works well, except its
not
| in
| > | the
| > | > | framework i just mentioned. Adding my control dynamically to the
| > | > datalist's
| > | > | item may be the root of the cause. i've made sure all custom
| controls
| > | > | implmenet INamingContainer & I think all controls have their id's
| set,
| > | so
| > | > | what else can i do?
| > | > |
| > | > | thanks a bunch
| > | > |
| > | > | | > | > | > I have figured the cause of the problem, sort of. My main
control
| > was
| > | > | being
| > | > | > loaded dynamically during a custom data list control's
| ItemDataBound
| > | > | event,
| > | > | > and then added to the e.item.controls collection. Once I removed
| it
| > | from
| > | > | > here, the correct event was called in my control. the problem
is i
| > | need
| > | > to
| > | > | > keep it where it is because of the way the page works.
| > | > | >
| > | > | > I tried to add INamingContainer to the custom Datalist, but that
| > | didn't
| > | > | > help. Any ideas what could make this happen?
| > | > | >
| > | > | > thanks so much, i know i'm being a pain, but i'm stuck!
| > | > | >
| > | > | > This is the custom DataLists' event:
| > | > | > protected override void OnItemDataBound(DataListItemEventArgs e)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > base.OnItemDataBound(e);
| > | > | >
| > | > | > Parameter parameter = (Parameter)e.Item.DataItem;
| > | > | >
| > | > | > try
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Control control;
| > | > | >
| > | > | > if(parameter.Type == ParameterType.Control)
| > | > | >
| > | > | > control = this.Page.LoadControl(parameter.ControlPath);
| > | > | >
| > | > | > else
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Assembly assembly = parameter.Assembly;
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > // The control didn't declare its own assembly, so use the
| report's
| > | > | > ControlsAssembly
| > | > | >
| > | > | > assembly = this.ControlsAssembly;
| > | > | >
| > | > | > // Ther report's ControlsAssembly is null, so use current page's
| > | > assembly
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > assembly = this.Page.GetType().BaseType.Assembly;
| > | > | >
| > | > | > }
| > | > | >
| > | > | >
| > | > | > control = (Control)
| > | assembly.CreateInstance(parameter.ControlTypeName);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > control.ID = parameter.Name;
| > | > | >
| > | > | > // Set up all the properties of this control from the
| > | > parameter.properties
| > | > | >
| > | > | > foreach(DictionaryEntry de in parameter.Properties)
| > | > | >
| > | > | > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| > | > | >
| > | > | >
| > | > | > e.Item.Controls.Add(control);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > catch (Exception ex)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > throw new ApplicationException("Unable to render criteria.
Reason:
| > " +
| > | > | > ex.Message, ex);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > }
| > | > | >
| > | > | > | > | > | > > In testing, i removed the main parent dropdown and only left
the
| 2
| > | > below
| > | > | > it.
| > | > | > > this time, the same scenario happened...when the child
dropdown
| > list
| > | > | > > autopostsback, it's immediate parent's selectedindexchanged
| event
| > | > fires!
| > | > | I
| > | > | > 'm
| > | > | > > starting to pull my hair out now...I"m stuck!
| > | > | > >
| > | > | > > please help superman
| > | > | > >
| > | > | > > | > | > | > > > Another problem:
| > | > | > > >
| > | > | > > > while i'm waiting on your remark to my last post, i removed
| the
| > | sub
| > | > | > > > composite controls from my composite control so that there
is
| > only
| > | > | drop
| > | > | > > down
| > | > | > > > lists on it. During CreateChildcontrols, i load the main
drop
| > down
| > | > | using
| > | > | > > > databind. When the page is sent to browser for the first
time,
| i
| > | > have
| > | > | my
| > | > | > > > main drop down filled. I then select an item and its
| > | > | > SelectedIndexChanged
| > | > | > > > fires and populates the send drop down list. Then when i
| select
| > an
| > | > | item
| > | > | > > from
| > | > | > > > it, it posts back, and the event that gets called is the
| > | main(first)
| > | > | > > > dropdown list's SelectedIndexChanged event, which then
| > | re-populates
| > | > | the
| > | > | > > > second drop down list, then the control returns to the
browser
| > | (The
| > | > | > > > SelectedIndexChanged event never fired for the 2nd
dropdown's
| > | > changed
| > | > | > > > event.???
| > | > | > > >
| > | > | > > > thanks again
| > | > | > > >
| > | > | > > > using System;
| > | > | > > >
| > | > | > > > using System.Collections.Specialized;
| > | > | > > >
| > | > | > > > using System.Web.UI;
| > | > | > > >
| > | > | > > > using System.Web.UI.WebControls;
| > | > | > > >
| > | > | > > > using System.Text;
| > | > | > > >
| > | > | > > > using OperationsTeams.Business;
| > | > | > > >
| > | > | > > > using OperationsTeams.Data;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting.WebControls;
| > | > | > > >
| > | > | > > > namespace OperationsTeams.Web.ReportControls
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > /// <summary>
| > | > | > > >
| > | > | > > > /// Summary description for FiscalAgentHierarchy.
| > | > | > > >
| > | > | > > > /// </summary>
| > | > | > > >
| > | > | > > > public class FiscalAgentHierarchy : WebControl,
| > | > | IReportParameterControl,
| > | > | > > > INamingContainer
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > protected override void OnLoad(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnLoad (e);
| > | > | > > >
| > | > | > > >
| > | > | > > > // The last state of controls from viewstate is now loaded
| > (Before
| > | > the
| > | > | > > > client data is processed)
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | > | > > > protected override void OnPreRender(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnPreRender (e);
| > | > | > > >
| > | > | > > > // The controls now have the client values from the the last
| > | > postback
| > | > | > > >
| > | > | > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > | > | > > >
| > | > | > > > // ddlProviders.Visible = ProviderVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Visible = SiteVisible;
| > | > | > > >
| > | > | > > > // ddlClasses.Visible = ClassVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > > // ddlSites.Visible = true;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > 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 ddlFundingSource_SelectedIndexChanged(object
| > sender,
| > | > | > > EventArgs
| > | > | > > > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlProviders_SelectedIndexChanged(object
sender,
| > | > | EventArgs
| > | > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlSites_SelectedIndexChanged(object sender,
| > | EventArgs
| > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > protected override void CreateChildControls()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > this.ddlFundingSource = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlProviders = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlSites = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlClasses = new DropDownList();
| > | > | > > >
| > | > | > > > ddlFundingSource.ID = FundingSourceControlId;
| > | > | > > >
| > | > | > > > ddlProviders.ID = ProvidersControlId;
| > | > | > > >
| > | > | > > > ddlSites.ID = SitesControlId;
| > | > | > > >
| > | > | > > > ddlClasses.ID = ClassesControlId;
| > | > | > > >
| > | > | > > >
| > | > | > > > LoadProviders();
| > | > | > > >
| > | > | > > > // 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>"));
| > | > | > > >
| > | > | > > > ddlFundingSource.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlProviders.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlSites.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlSites_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > | > | > > > ddlSites.AutoPostBack = true;
| > | > | > > >
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadFundingSource()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
| > 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = 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
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadProviders()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
1;//fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > >
| > | > | > > >
| > | > | > > > ProviderVisible = true;
| > | > | > > >
| > | > | > > > // are these dates correct???????????????????????????
| > | > | > > >
| > | > | > > > ddlProviders.DataSource =
| > FiscalAgentProvider.Find(fiscalAgentId,
| > | > new
| > | > | > > > DateTime(2005,7,1), new
| > | > | > > >
| > | > |
| > DateTime(2006,6,30));//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();
| > | > | > > >
| > | > | > > > ProviderVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadSites()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlProviders.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // Load the Site search parameters.
| > | > | > > >
| > | > | > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > | > | > > >
| > | > | > > > siteFindArgs.FiscalAgentId=1;
| > | > | > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > SiteVisible = 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();
| > | > | > > >
| > | > | > > > SiteVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadClasses()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlSites.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| > | > | AdultEdClassFindArgs();
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.FiscalAgentId =
| > | > | > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > | > | > > > rysReportingYearSelector.ReportingYearStartDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > | > | > > > rysReportingYearSelector.ReportingYearEndDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ProviderName =
| > ddlProviders.SelectedValue;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > | > | > > >
| > | > | > > >
| > | > | > > > ClassVisible = true;
| > | > | > > >
| > | > | > > > ddlClasses.DataSource =
| AdultEdClass.Find(adultEdClassFindArgs);
| > | > | > > >
| > | > | > > > ddlClasses.DataTextField = "Name";
| > | > | > > >
| > | > | > > > ddlClasses.DataValueField = "ClassId";
| > | > | > > >
| > | > | > > > ddlClasses.DataBind();
| > | > | > > >
| > | > | > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
| > | > string.Empty));
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > else
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > ddlClasses.Items.Clear();
| > | > | > > >
| > | > | > > > ClassVisible = 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
| > | > | > > >
| > | > | > > > protected bool FundingSourceVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["FundingSourceVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["FundingSourceVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["FundingSourceVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ProviderVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ProviderVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ProviderVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ProviderVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool SiteVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["SiteVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["SiteVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["SiteVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ClassVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ClassVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ClassVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ClassVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > #region Private Member Variables
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | message
| > | > | > > > | > | > | > > > > Hi TS,
| > | > | > > > >
| > | > | > > > > See you again :), seems you're rushing in a asp.net
project
| > | these
| > | > | > days?
| > | > | > > > > For the question you mentioned in this post, here are some
| of
| > my
| > | > | > > > > understanding and suggestions:
| > | > | > > > >
| > | > | > > > > 1. ASP.NET controls derived from Control will
automatically
| > | > maintain
| > | > | > its
| > | > | > > > > ViewStates according to the asp.net web page's events
| > sequence.
| > | So
| > | > | for
| > | > | > > > > composite control, those nested sub Controls' status
| > (properties
| > | > | which
| > | > | > > be
| > | > | > > > > persistd in Viewsstate ) will be store and retrieve
| > | automatically.
| > | > | > > > >
| > | > | > > > > 2. However, there're some thing we need to care when
| building
| > | > | > composite
| > | > | > > > > control:
| > | > | > > > > #remember to implement INamingContainer for controls which
| > will
| > | > have
| > | > | > > > nested
| > | > | > > > > sub controls. Otherwise, even handler mapping, ViewState
| > loading
| > | > | will
| > | > | > > > occur
| > | > | > > > > unexpectedly.
| > | > | > > > >
| > | > | > > > > #Do remember to assign a explicit ID for each sub
| > controls(same
| > | > | reason
| > | > | > > as
| > | > | > > > > #1). Also, please always try best to add subcontrols in
the
| > | > | > > > > "CreateChildControls" method(just create control
hierarchy)
| > and
| > | > put
| > | > | > > > > manipulating code in postback event or PreRender event.
| > | > | > > > >
| > | > | > > > > In addition, for your detaile scenario, I've just built a
| very
| > | > | simple
| > | > | > > demo
| > | > | > > > > control which have three dropdownlists and The "Top" one
| will
| > | > | display
| > | > | > > > > first(other twos invisible) and according to the top one's
| > | > | selection,
| > | > | > > the
| > | > | > > > > "Mid" dropdownlist will be pouplated and the same when the
| > | "mid"'s
| > | > | > > > > selection changed......
| > | > | > > > >
| > | > | > > > > Here's the control's code for your reference:
| > | > | > > > >
| > | > | > > > > =========================
| > | > | > > > > [DefaultProperty("Text"),
| > | > | > > > > ToolboxData("<{0}:MultiListControl
| > | > | > > runat=server></{0}:MultiListControl>")]
| > | > | > > > > public class MultiListControl :
| > | > | System.Web.UI.WebControls.WebControl,
| > | > | > > > > INamingContainer
| > | > | > > > > {
| > | > | > > > > private string text;
| > | > | > > > >
| > | > | > > > > private DropDownList lstTop;
| > | > | > > > > private DropDownList lstMid;
| > | > | > > > > private DropDownList lstBot;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected bool MidVisible
| > | > | > > > > {
| > | > | > > > > get{
| > | > | > > > > if(ViewState["MID_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["MID_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set{
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["MID_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > protected bool BotVisible
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > if(ViewState["BOT_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["BOT_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["BOT_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > [Bindable(true),
| > | > | > > > > Category("Appearance"),
| > | > | > > > > DefaultValue("")]
| > | > | > > > > public string Text
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > return text;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > text = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void CreateChildControls()
| > | > | > > > > {
| > | > | > > > > Controls.Clear();
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > <table width='100%'>
| > | > | > > > > <tr><td>
| > | > | > > > > "));
| > | > | > > > >
| > | > | > > > > lstTop = new DropDownList();
| > | > | > > > > lstTop.ID = "lstTop";
| > | > | > > > >
| > | > | > > > > lstTop.Items.Add("----------");
| > | > | > > > > lstTop.Items.Add("Top_Item_1");
| > | > | > > > > lstTop.Items.Add("Top_Item_2");
| > | > | > > > > lstTop.Items.Add("Top_Item_3");
| > | > | > > > > lstTop.Items.Add("Top_Item_4");
| > | > | > > > >
| > | > | > > > > Controls.Add(lstTop);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > > lstMid = new DropDownList();
| > | > | > > > > lstMid.ID = "lstMid";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstMid);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstBot = new DropDownList();
| > | > | > > > > lstBot.ID = "lstBot";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstBot);
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > </td></tr>
| > | > | > > > > </table>
| > | > | > > > > "
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstTop.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstMid.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstBot.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > >
| > | > | > > > > lstTop.AutoPostBack = lstMid.AutoPostBack =
| > lstBot.AutoPostBack
| > | =
| > | > | > true;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void OnPreRender(EventArgs e)
| > | > | > > > > {
| > | > | > > > > base.OnPreRender (e);
| > | > | > > > >
| > | > | > > > > lstMid.Visible = MidVisible;
| > | > | > > > > lstBot.Visible = BotVisible;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > private void lst_SelectedIndexChanged(object sender,
| > | > | System.EventArgs
| > | > | > e)
| > | > | > > > > {
| > | > | > > > >
| > | > | > > > > DropDownList lst = sender as DropDownList;
| > | > | > > > >
| > | > | > > > > switch(lst.ID)
| > | > | > > > > {
| > | > | > > > > case "lstTop":
| > | > | > > > >
| > | > | > > > > if(lst.SelectedIndex != 0)
| > | > | > > > > {
| > | > | > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstMid.DataTextField = "Text";
| > | > | > > > > lstMid.DataValueField= "Value";
| > | > | > > > > lstMid.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = true;
| > | > | > > > > }
| > | > | > > > > else
| > | > | > > > > {
| > | > | > > > > MidVisible = BotVisible = false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstMid":
| > | > | > > > >
| > | > | > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstBot.DataTextField = "Text";
| > | > | > > > > lstBot.DataValueField= "Value";
| > | > | > > > > lstBot.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = BotVisible = true;
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstBot":
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > Page.Response.Write("<br>" + lst.ID +
| > "_selectedindexchanged!" +
| > | > | > > > > lst.EnableViewState);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > #region --Helper functions---
| > | > | > > > >
| > | > | > > > > public ListItemCollection GetSubItems(string parent)
| > | > | > > > > {
| > | > | > > > > ListItemCollection items = new ListItemCollection();
| > | > | > > > > int count = parent.Length;
| > | > | > > > >
| > | > | > > > > for(int i=0;i<count;++i)
| > | > | > > > > {
| > | > | > > > > items.Add(parent + "_Item_" + i);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return items;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > #endregion
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > ========================
| > | > | > > > > Hope helps. Thanks,
| > | > | > > > >
| > | > | > > > > Steven Cheng
| > | > | > > > > Microsoft Online Support
| > | > | > > > >
| > | > | > > > > Get Secure! www.microsoft.com/security
| > | > | > > > > (This posting is provided "AS IS", with no warranties, and
| > | confers
| > | > | no
| > | > | > > > > rights.)
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > --------------------
| > | > | > > > > | From: "TS" <[email protected]>
| > | > | > > > > | References: <[email protected]>
| > | > | > > > > | Subject: Re: explanation of when need to repopulate
| control
| > | > | > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > | > | > > > > | Lines: 39
| > | > | > > > > | X-Priority: 3
| > | > | > > > > | X-MSMail-Priority: Normal
| > | > | > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | > > > > | Message-ID: <[email protected]>
| > | > | > > > > | Newsgroups:
| > | > | > > > >
| > | > | > > >
| > | > | > >
| > | > | >
| > | > |
| > | >
| > |
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > | > | > > > > framework.aspnet.buildingcontrols
| > | > | > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us
| 198.214.103.100
| > | > | > > > > | Path:
| > | > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | > | > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > | > > > >
| microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > | > | > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > | > | > > > > | X-Tomcat-NG:
| > | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | > > > > |
| > | > | > > > > | sorry, heres the scenario i'm trying to accomplish:
| > | > | > > > > | I have a composite control that contains 4 drop down
| lists.
| > | When
| > | > | the
| > | > | > > > page
| > | > | > > > > | loads initially, i want the first drop down filled and
the
| > | rest
| > | > | > > > invisible.
| > | > | > > > > | When you select an item in this ddl, it posts back to
the
| > | server
| > | > | and
| > | > | > > > based
| > | > | > > > > | on its value, it populates its immediate child's drop
down
| > | list.
| > | > | So
| > | > | > > now
| > | > | > > > > the
| > | > | > > > > | top ddl has a value selected and the 2nd one just has
its
| > | items
| > | > | > > > populated.
| > | > | > > > > | Then when the 2nd drop down list gets selected, it posts
| to
| > | the
| > | > | > server
| > | > | > > > and
| > | > | > > > > | its value is used to populate(filter) the items for the
| 3rd
| > | drop
| > | > | > down
| > | > | > > > > | list...and so on for each drop down list.
| > | > | > > > > |
| > | > | > > > > | Please tell me what i need to do to handle post back
data
| > and
| > | > | > maintain
| > | > | > > > > state
| > | > | > > > > | from one postback to another while keeping the drop
| > downlists
| > | > | filled
| > | > | > > and
| > | > | > > > > | their values persisted.
| > | > | > > > > |
| > | > | > > > > | thank you again!
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > | | > | > | > > > > | > I have a quesiton:
| > | > | > > > > | > if i have a composite control and on its intial page
| > | loading,
| > | > i
| > | > | > fill
| > | > | > > > my
| > | > | > > > > | (sub
| > | > | > > > > | > control) drop down list's items collection from the
| > database
| > | > and
| > | > | > > > return.
| > | > | > > > > | > When the user hits a button to cause postback, the
| control
| > | is
| > | > | > going
| > | > | > > to
| > | > | > > > > get
| > | > | > > > > | > initialized, then does its items collection that i
| filled
| > on
| > | > the
| > | > | > > > initial
| > | > | > > > > | > page request get repopulated from viewstate? And on
top
| of
| > | > that,
| > | > | > if
| > | > | > > > so,
| > | > | > > > > | does
| > | > | > > > > | > the list item that person selected in the drop down
list
| > | again
| > | > | set
| > | > | > > > > itself
| > | > | > > > > | as
| > | > | > > > > | > the selected item in the list?
| > | > | > > > > | >
| > | > | > > > > | > OR do i have to re-load the items on every page
request
| > and
| > | > then
| > | > | > > > > populate
| > | > | > > > > | > its value some other way???
| > | > | > > > > | >
| > | > | > > > > | > thanks a bunch
| > | > | > > > > | >
| > | > | > > > > | >
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > >
| > | > | > > >
| > | > | > > >
| > | > | > >
| > | > | > >
| > | > | >
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
T

TS

Hey Steven, I have a problem while working with the same DataList control.
That one problem that caused the wrong event handler to get called is
happening now. I am working on a different project using the same control
that i got finished on the other project and trying to implement on this new
project, and it is set up almost the same. The only difference is that on
this new one, i have added a postback step before the custom datalist gets
loaded.

Any ideas as why the wrong event handler is getting called?

thanks

Steven Cheng said:
You're welcome TS.

Glad that you've overcome the problem.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Mon, 8 Aug 2005 12:50:32 -0500
| Lines: 1445
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4014
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well you were right that it had something to do with the custom control.
The
| datalist was trying to load itself during page load. i put the code in
Init,
| and it worked.
|
| thanks steven
|
| | > Thanks for your followup TS.
| >
| > So can I say that currently your custom webcontrol(not template list
| > control) can correctly be added both statically and dynamically in the
| > normal DataList or Repeater controls (asp.net buildin ) , but have some
| > problem for postback events when added in your custom list control?
| >
| > If so, we should keep focus on the custom datalist control. Has it any
| > problems when we nest some asp.net buildin controls in it? Would you try
| > making a simplified version of your custom datalist control so that we
can
| > have a view to see whether there is anything wrong in it. Also, it'll be
| > helpful you also provide the complete code that you dynamically add
| control
| > into the datalist (through reflection).
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "TS" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <unRs#[email protected]>
| > <[email protected]>
| > <#[email protected]>
| > <[email protected]>
| > | Subject: Re: explanation of when need to repopulate control
| > | Date: Fri, 5 Aug 2005 17:19:23 -0500
| > | Lines: 1298
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:4003
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | I have a new problem now. I have figured out that the cause is the
same
| > | reason. If its in the custom DataList, it doesn't work, else it does
| work.
| > |
| > | The scenario:
| > | After the initial page load, you enter data into controls and hit
submit
| > | button, the process is as follows:
| > | Page_Load
| > | DataList's OnLoad
| > | Composite Control's OnLoad
| > | Submit button's OnClick - At this point, the controls in the composite
| > | control have no listitems and no selectedValue properties.
| > |
| > | I have statically added the composite control onto the same page as
the
| > | dynamic one, so here is the process in this scenario:
| > | Page_Load
| > | Composite Control's OnLoad (The one whose parent is Page)
| > | DataList's OnLoad
| > | Composite Control's OnLoad (The one whose parent is the Custom
DataList)
| > | Submit button's OnClick - At this point, the controls in the
statically
| > | declared composite control have listitems and have values for
| > selectedValue
| > | properties.
| > |
| > | So the same control at the same time - the one outside the custom
| Datalist
| > | has its controls' state set up correctly, the ones inside does not.
| > |
| > | So the same reason is at play here. Maybe since i am dynamically
| creating
| > | the class using reflection (Assembly.CreateInstance()) that has
| something
| > to
| > | do with it?
| > |
| > | Please help mr. Cheng.
| > |
| > | Thank you very much!
| > |
| > | TS
| > |
| > |
| > |
| > | | > | > Hi TS,
| > | >
| > | > First, I'm glad that you've got your composite control work, all the
| > | > dropdownlist's postback events can fire correctly,yes?
| > | >
| > | > As for the new problem you encountered when adding your composite
| > control
| > | > into DataList's item, is the DataList the asp.net's buildin DataList
| > | > control? And since you mentioned that you dynamically add your
| control
| > | > into it, how do you dynamically add your custom control? Will there
| > occur
| > | > problem if you statically add your control into DataList?
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | > --------------------
| > | > | From: "TS" <[email protected]>
| > | > | References: <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <unRs#[email protected]>
| > | > <[email protected]>
| > | > | Subject: Re: explanation of when need to repopulate control
| > | > | Date: Wed, 3 Aug 2005 19:07:16 -0500
| > | > | Lines: 1153
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | > | Path:
| TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| > | > | X-Tomcat-NG:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > |
| > | > | Well Steve, I am almost done. My control works well, except its
not
| in
| > | the
| > | > | framework i just mentioned. Adding my control dynamically to the
| > | > datalist's
| > | > | item may be the root of the cause. i've made sure all custom
| controls
| > | > | implmenet INamingContainer & I think all controls have their id's
| set,
| > | so
| > | > | what else can i do?
| > | > |
| > | > | thanks a bunch
| > | > |
| > | > | | > | > | > I have figured the cause of the problem, sort of. My main
control
| > was
| > | > | being
| > | > | > loaded dynamically during a custom data list control's
| ItemDataBound
| > | > | event,
| > | > | > and then added to the e.item.controls collection. Once I removed
| it
| > | from
| > | > | > here, the correct event was called in my control. the problem
is i
| > | need
| > | > to
| > | > | > keep it where it is because of the way the page works.
| > | > | >
| > | > | > I tried to add INamingContainer to the custom Datalist, but that
| > | didn't
| > | > | > help. Any ideas what could make this happen?
| > | > | >
| > | > | > thanks so much, i know i'm being a pain, but i'm stuck!
| > | > | >
| > | > | > This is the custom DataLists' event:
| > | > | > protected override void OnItemDataBound(DataListItemEventArgs e)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > base.OnItemDataBound(e);
| > | > | >
| > | > | > Parameter parameter = (Parameter)e.Item.DataItem;
| > | > | >
| > | > | > try
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Control control;
| > | > | >
| > | > | > if(parameter.Type == ParameterType.Control)
| > | > | >
| > | > | > control = this.Page.LoadControl(parameter.ControlPath);
| > | > | >
| > | > | > else
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Assembly assembly = parameter.Assembly;
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > // The control didn't declare its own assembly, so use the
| report's
| > | > | > ControlsAssembly
| > | > | >
| > | > | > assembly = this.ControlsAssembly;
| > | > | >
| > | > | > // Ther report's ControlsAssembly is null, so use current page's
| > | > assembly
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > assembly = this.Page.GetType().BaseType.Assembly;
| > | > | >
| > | > | > }
| > | > | >
| > | > | >
| > | > | > control = (Control)
| > | assembly.CreateInstance(parameter.ControlTypeName);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > control.ID = parameter.Name;
| > | > | >
| > | > | > // Set up all the properties of this control from the
| > | > parameter.properties
| > | > | >
| > | > | > foreach(DictionaryEntry de in parameter.Properties)
| > | > | >
| > | > | > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| > | > | >
| > | > | >
| > | > | > e.Item.Controls.Add(control);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > catch (Exception ex)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > throw new ApplicationException("Unable to render criteria.
Reason:
| > " +
| > | > | > ex.Message, ex);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > }
| > | > | >
| > | > | > | > | > | > > In testing, i removed the main parent dropdown and only left
the
| 2
| > | > below
| > | > | > it.
| > | > | > > this time, the same scenario happened...when the child
dropdown
| > list
| > | > | > > autopostsback, it's immediate parent's selectedindexchanged
| event
| > | > fires!
| > | > | I
| > | > | > 'm
| > | > | > > starting to pull my hair out now...I"m stuck!
| > | > | > >
| > | > | > > please help superman
| > | > | > >
| > | > | > > | > | > | > > > Another problem:
| > | > | > > >
| > | > | > > > while i'm waiting on your remark to my last post, i removed
| the
| > | sub
| > | > | > > > composite controls from my composite control so that there
is
| > only
| > | > | drop
| > | > | > > down
| > | > | > > > lists on it. During CreateChildcontrols, i load the main
drop
| > down
| > | > | using
| > | > | > > > databind. When the page is sent to browser for the first
time,
| i
| > | > have
| > | > | my
| > | > | > > > main drop down filled. I then select an item and its
| > | > | > SelectedIndexChanged
| > | > | > > > fires and populates the send drop down list. Then when i
| select
| > an
| > | > | item
| > | > | > > from
| > | > | > > > it, it posts back, and the event that gets called is the
| > | main(first)
| > | > | > > > dropdown list's SelectedIndexChanged event, which then
| > | re-populates
| > | > | the
| > | > | > > > second drop down list, then the control returns to the
browser
| > | (The
| > | > | > > > SelectedIndexChanged event never fired for the 2nd
dropdown's
| > | > changed
| > | > | > > > event.???
| > | > | > > >
| > | > | > > > thanks again
| > | > | > > >
| > | > | > > > using System;
| > | > | > > >
| > | > | > > > using System.Collections.Specialized;
| > | > | > > >
| > | > | > > > using System.Web.UI;
| > | > | > > >
| > | > | > > > using System.Web.UI.WebControls;
| > | > | > > >
| > | > | > > > using System.Text;
| > | > | > > >
| > | > | > > > using OperationsTeams.Business;
| > | > | > > >
| > | > | > > > using OperationsTeams.Data;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting.WebControls;
| > | > | > > >
| > | > | > > > namespace OperationsTeams.Web.ReportControls
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > /// <summary>
| > | > | > > >
| > | > | > > > /// Summary description for FiscalAgentHierarchy.
| > | > | > > >
| > | > | > > > /// </summary>
| > | > | > > >
| > | > | > > > public class FiscalAgentHierarchy : WebControl,
| > | > | IReportParameterControl,
| > | > | > > > INamingContainer
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > protected override void OnLoad(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnLoad (e);
| > | > | > > >
| > | > | > > >
| > | > | > > > // The last state of controls from viewstate is now loaded
| > (Before
| > | > the
| > | > | > > > client data is processed)
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | > | > > > protected override void OnPreRender(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnPreRender (e);
| > | > | > > >
| > | > | > > > // The controls now have the client values from the the last
| > | > postback
| > | > | > > >
| > | > | > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > | > | > > >
| > | > | > > > // ddlProviders.Visible = ProviderVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Visible = SiteVisible;
| > | > | > > >
| > | > | > > > // ddlClasses.Visible = ClassVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > > // ddlSites.Visible = true;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > 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 ddlFundingSource_SelectedIndexChanged(object
| > sender,
| > | > | > > EventArgs
| > | > | > > > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlProviders_SelectedIndexChanged(object
sender,
| > | > | EventArgs
| > | > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlSites_SelectedIndexChanged(object sender,
| > | EventArgs
| > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > protected override void CreateChildControls()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > this.ddlFundingSource = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlProviders = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlSites = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlClasses = new DropDownList();
| > | > | > > >
| > | > | > > > ddlFundingSource.ID = FundingSourceControlId;
| > | > | > > >
| > | > | > > > ddlProviders.ID = ProvidersControlId;
| > | > | > > >
| > | > | > > > ddlSites.ID = SitesControlId;
| > | > | > > >
| > | > | > > > ddlClasses.ID = ClassesControlId;
| > | > | > > >
| > | > | > > >
| > | > | > > > LoadProviders();
| > | > | > > >
| > | > | > > > // start containing table
| > | > | > > >
| > | > | > > > this.Controls.Add(WebHelper.MakeLiteral("<table
cellpadding=0
| > | > | > > > cellspacing=0><tr><td>"));
| > | > | > > >
| > | > | > > >
| > | > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > | > > >
| > | > | > > > // 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( said:
| > | > | > > >
| > | > | > > > // 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( said:
| > | > | > > > );
| > | > | > > >
| > | > | > > > 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( said:
| > | > | > > >
| > | > | > > > this.Controls.Add(ddlClasses);
| > | > | > > >
| > | > | > > >
| this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > | > | > > >
| > | > | > > > // end containing table
| > | > | > > >
| > | > | > > >
| this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > | > | > > >
| > | > | > > > ddlFundingSource.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlProviders.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlSites.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlSites_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > | > | > > > ddlSites.AutoPostBack = true;
| > | > | > > >
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadFundingSource()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
| > 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = 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
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadProviders()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
1;//fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > >
| > | > | > > >
| > | > | > > > ProviderVisible = true;
| > | > | > > >
| > | > | > > > // are these dates correct???????????????????????????
| > | > | > > >
| > | > | > > > ddlProviders.DataSource =
| > FiscalAgentProvider.Find(fiscalAgentId,
| > | > new
| > | > | > > > DateTime(2005,7,1), new
| > | > | > > >
| > | > |
| > DateTime(2006,6,30));//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();
| > | > | > > >
| > | > | > > > ProviderVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadSites()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlProviders.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // Load the Site search parameters.
| > | > | > > >
| > | > | > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > | > | > > >
| > | > | > > > siteFindArgs.FiscalAgentId=1;
| > | > | > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > SiteVisible = 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();
| > | > | > > >
| > | > | > > > SiteVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadClasses()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlSites.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| > | > | AdultEdClassFindArgs();
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.FiscalAgentId =
| > | > | > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > | > | > > > rysReportingYearSelector.ReportingYearStartDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > | > | > > > rysReportingYearSelector.ReportingYearEndDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ProviderName =
| > ddlProviders.SelectedValue;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > | > | > > >
| > | > | > > >
| > | > | > > > ClassVisible = true;
| > | > | > > >
| > | > | > > > ddlClasses.DataSource =
| AdultEdClass.Find(adultEdClassFindArgs);
| > | > | > > >
| > | > | > > > ddlClasses.DataTextField = "Name";
| > | > | > > >
| > | > | > > > ddlClasses.DataValueField = "ClassId";
| > | > | > > >
| > | > | > > > ddlClasses.DataBind();
| > | > | > > >
| > | > | > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
| > | > string.Empty));
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > else
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > ddlClasses.Items.Clear();
| > | > | > > >
| > | > | > > > ClassVisible = 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
| > | > | > > >
| > | > | > > > protected bool FundingSourceVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["FundingSourceVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["FundingSourceVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["FundingSourceVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ProviderVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ProviderVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ProviderVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ProviderVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool SiteVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["SiteVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["SiteVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["SiteVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ClassVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ClassVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ClassVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ClassVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > #region Private Member Variables
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | message
| > | > | > > > | > | > | > > > > Hi TS,
| > | > | > > > >
| > | > | > > > > See you again :), seems you're rushing in a asp.net
project
| > | these
| > | > | > days?
| > | > | > > > > For the question you mentioned in this post, here are some
| of
| > my
| > | > | > > > > understanding and suggestions:
| > | > | > > > >
| > | > | > > > > 1. ASP.NET controls derived from Control will
automatically
| > | > maintain
| > | > | > its
| > | > | > > > > ViewStates according to the asp.net web page's events
| > sequence.
| > | So
| > | > | for
| > | > | > > > > composite control, those nested sub Controls' status
| > (properties
| > | > | which
| > | > | > > be
| > | > | > > > > persistd in Viewsstate ) will be store and retrieve
| > | automatically.
| > | > | > > > >
| > | > | > > > > 2. However, there're some thing we need to care when
| building
| > | > | > composite
| > | > | > > > > control:
| > | > | > > > > #remember to implement INamingContainer for controls which
| > will
| > | > have
| > | > | > > > nested
| > | > | > > > > sub controls. Otherwise, even handler mapping, ViewState
| > loading
| > | > | will
| > | > | > > > occur
| > | > | > > > > unexpectedly.
| > | > | > > > >
| > | > | > > > > #Do remember to assign a explicit ID for each sub
| > controls(same
| > | > | reason
| > | > | > > as
| > | > | > > > > #1). Also, please always try best to add subcontrols in
the
| > | > | > > > > "CreateChildControls" method(just create control
hierarchy)
| > and
| > | > put
| > | > | > > > > manipulating code in postback event or PreRender event.
| > | > | > > > >
| > | > | > > > > In addition, for your detaile scenario, I've just built a
| very
| > | > | simple
| > | > | > > demo
| > | > | > > > > control which have three dropdownlists and The "Top" one
| will
| > | > | display
| > | > | > > > > first(other twos invisible) and according to the top one's
| > | > | selection,
| > | > | > > the
| > | > | > > > > "Mid" dropdownlist will be pouplated and the same when the
| > | "mid"'s
| > | > | > > > > selection changed......
| > | > | > > > >
| > | > | > > > > Here's the control's code for your reference:
| > | > | > > > >
| > | > | > > > > =========================
| > | > | > > > > [DefaultProperty("Text"),
| > | > | > > > > ToolboxData("<{0}:MultiListControl
| > | > | > > runat=server></{0}:MultiListControl>")]
| > | > | > > > > public class MultiListControl :
| > | > | System.Web.UI.WebControls.WebControl,
| > | > | > > > > INamingContainer
| > | > | > > > > {
| > | > | > > > > private string text;
| > | > | > > > >
| > | > | > > > > private DropDownList lstTop;
| > | > | > > > > private DropDownList lstMid;
| > | > | > > > > private DropDownList lstBot;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected bool MidVisible
| > | > | > > > > {
| > | > | > > > > get{
| > | > | > > > > if(ViewState["MID_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["MID_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set{
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["MID_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > protected bool BotVisible
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > if(ViewState["BOT_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["BOT_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["BOT_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > [Bindable(true),
| > | > | > > > > Category("Appearance"),
| > | > | > > > > DefaultValue("")]
| > | > | > > > > public string Text
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > return text;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > text = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void CreateChildControls()
| > | > | > > > > {
| > | > | > > > > Controls.Clear();
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > <table width='100%'>
| > | > | > > > > <tr><td>
| > | > | > > > > "));
| > | > | > > > >
| > | > | > > > > lstTop = new DropDownList();
| > | > | > > > > lstTop.ID = "lstTop";
| > | > | > > > >
| > | > | > > > > lstTop.Items.Add("----------");
| > | > | > > > > lstTop.Items.Add("Top_Item_1");
| > | > | > > > > lstTop.Items.Add("Top_Item_2");
| > | > | > > > > lstTop.Items.Add("Top_Item_3");
| > | > | > > > > lstTop.Items.Add("Top_Item_4");
| > | > | > > > >
| > | > | > > > > Controls.Add(lstTop);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > > lstMid = new DropDownList();
| > | > | > > > > lstMid.ID = "lstMid";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstMid);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstBot = new DropDownList();
| > | > | > > > > lstBot.ID = "lstBot";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstBot);
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > </td></tr>
| > | > | > > > > </table>
| > | > | > > > > "
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstTop.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstMid.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstBot.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > >
| > | > | > > > > lstTop.AutoPostBack = lstMid.AutoPostBack =
| > lstBot.AutoPostBack
| > | =
| > | > | > true;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void OnPreRender(EventArgs e)
| > | > | > > > > {
| > | > | > > > > base.OnPreRender (e);
| > | > | > > > >
| > | > | > > > > lstMid.Visible = MidVisible;
| > | > | > > > > lstBot.Visible = BotVisible;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > private void lst_SelectedIndexChanged(object sender,
| > | > | System.EventArgs
| > | > | > e)
| > | > | > > > > {
| > | > | > > > >
| > | > | > > > > DropDownList lst = sender as DropDownList;
| > | > | > > > >
| > | > | > > > > switch(lst.ID)
| > | > | > > > > {
| > | > | > > > > case "lstTop":
| > | > | > > > >
| > | > | > > > > if(lst.SelectedIndex != 0)
| > | > | > > > > {
| > | > | > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstMid.DataTextField = "Text";
| > | > | > > > > lstMid.DataValueField= "Value";
| > | > | > > > > lstMid.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = true;
| > | > | > > > > }
| > | > | > > > > else
| > | > | > > > > {
| > | > | > > > > MidVisible = BotVisible = false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstMid":
| > | > | > > > >
| > | > | > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstBot.DataTextField = "Text";
| > | > | > > > > lstBot.DataValueField= "Value";
| > | > | > > > > lstBot.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = BotVisible = true;
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstBot":
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > Page.Response.Write("<br>" + lst.ID +
| > "_selectedindexchanged!" +
| > | > | > > > > lst.EnableViewState);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > #region --Helper functions---
| > | > | > > > >
| > | > | > > > > public ListItemCollection GetSubItems(string parent)
| > | > | > > > > {
| > | > | > > > > ListItemCollection items = new ListItemCollection();
| > | > | > > > > int count = parent.Length;
| > | > | > > > >
| > | > | > > > > for(int i=0;i<count;++i)
| > | > | > > > > {
| > | > | > > > > items.Add(parent + "_Item_" + i);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return items;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > #endregion
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > ========================
| > | > | > > > > Hope helps. Thanks,
| > | > | > > > >
| > | > | > > > > Steven Cheng
| > | > | > > > > Microsoft Online Support
| > | > | > > > >
| > | > | > > > > Get Secure! www.microsoft.com/security
| > | > | > > > > (This posting is provided "AS IS", with no warranties, and
| > | confers
| > | > | no
| > | > | > > > > rights.)
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > --------------------
| > | > | > > > > | From: "TS" <[email protected]>
| > | > | > > > > | References: <[email protected]>
| > | > | > > > > | Subject: Re: explanation of when need to repopulate
| control
| > | > | > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > | > | > > > > | Lines: 39
| > | > | > > > > | X-Priority: 3
| > | > | > > > > | X-MSMail-Priority: Normal
| > | > | > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | > > > > | Message-ID: <[email protected]>
| > | > | > > > > | Newsgroups:
| > | > | > > > >
| > | > | > > >
| > | > | > >
| > | > | >
| > | > |
| > | >
| > |
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > | > | > > > > framework.aspnet.buildingcontrols
| > | > | > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us
| 198.214.103.100
| > | > | > > > > | Path:
| > | > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | > | > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > | > > > >
| microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > | > | > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > | > | > > > > | X-Tomcat-NG:
| > | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | > > > > |
| > | > | > > > > | sorry, heres the scenario i'm trying to accomplish:
| > | > | > > > > | I have a composite control that contains 4 drop down
| lists.
| > | When
| > | > | the
| > | > | > > > page
| > | > | > > > > | loads initially, i want the first drop down filled and
the
| > | rest
| > | > | > > > invisible.
| > | > | > > > > | When you select an item in this ddl, it posts back to
the
| > | server
| > | > | and
| > | > | > > > based
| > | > | > > > > | on its value, it populates its immediate child's drop
down
| > | list.
| > | > | So
| > | > | > > now
| > | > | > > > > the
| > | > | > > > > | top ddl has a value selected and the 2nd one just has
its
| > | items
| > | > | > > > populated.
| > | > | > > > > | Then when the 2nd drop down list gets selected, it posts
| to
| > | the
| > | > | > server
| > | > | > > > and
| > | > | > > > > | its value is used to populate(filter) the items for the
| 3rd
| > | drop
| > | > | > down
| > | > | > > > > | list...and so on for each drop down list.
| > | > | > > > > |
| > | > | > > > > | Please tell me what i need to do to handle post back
data
| > and
| > | > | > maintain
| > | > | > > > > state
| > | > | > > > > | from one postback to another while keeping the drop
| > downlists
| > | > | filled
| > | > | > > and
| > | > | > > > > | their values persisted.
| > | > | > > > > |
| > | > | > > > > | thank you again!
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > | | > | > | > > > > | > I have a quesiton:
| > | > | > > > > | > if i have a composite control and on its intial page
| > | loading,
| > | > i
| > | > | > fill
| > | > | > > > my
| > | > | > > > > | (sub
| > | > | > > > > | > control) drop down list's items collection from the
| > database
| > | > and
| > | > | > > > return.
| > | > | > > > > | > When the user hits a button to cause postback, the
| control
| > | is
| > | > | > going
| > | > | > > to
| > | > | > > > > get
| > | > | > > > > | > initialized, then does its items collection that i
| filled
| > on
| > | > the
| > | > | > > > initial
| > | > | > > > > | > page request get repopulated from viewstate? And on
top
| of
| > | > that,
| > | > | > if
| > | > | > > > so,
| > | > | > > > > | does
| > | > | > > > > | > the list item that person selected in the drop down
list
| > | again
| > | > | set
| > | > | > > > > itself
| > | > | > > > > | as
| > | > | > > > > | > the selected item in the list?
| > | > | > > > > | >
| > | > | > > > > | > OR do i have to re-load the items on every page
request
| > and
| > | > then
| > | > | > > > > populate
| > | > | > > > > | > its value some other way???
| > | > | > > > > | >
| > | > | > > > > | > thanks a bunch
| > | > | > > > > | >
| > | > | > > > > | >
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > >
| > | > | > > >
| > | > | > > >
| > | > | > >
| > | > | > >
| > | > | >
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
T

TS

i am not comfortable posting all my code here, but if you can provide me
with an email address or somewhere to upload my content, i can do that
(maybe you could create a temp hotmail account)


Steven Cheng said:
You're welcome TS.

Glad that you've overcome the problem.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Mon, 8 Aug 2005 12:50:32 -0500
| Lines: 1445
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4014
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well you were right that it had something to do with the custom control.
The
| datalist was trying to load itself during page load. i put the code in
Init,
| and it worked.
|
| thanks steven
|
| | > Thanks for your followup TS.
| >
| > So can I say that currently your custom webcontrol(not template list
| > control) can correctly be added both statically and dynamically in the
| > normal DataList or Repeater controls (asp.net buildin ) , but have some
| > problem for postback events when added in your custom list control?
| >
| > If so, we should keep focus on the custom datalist control. Has it any
| > problems when we nest some asp.net buildin controls in it? Would you try
| > making a simplified version of your custom datalist control so that we
can
| > have a view to see whether there is anything wrong in it. Also, it'll be
| > helpful you also provide the complete code that you dynamically add
| control
| > into the datalist (through reflection).
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "TS" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <unRs#[email protected]>
| > <[email protected]>
| > <#[email protected]>
| > <[email protected]>
| > | Subject: Re: explanation of when need to repopulate control
| > | Date: Fri, 5 Aug 2005 17:19:23 -0500
| > | Lines: 1298
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:4003
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | I have a new problem now. I have figured out that the cause is the
same
| > | reason. If its in the custom DataList, it doesn't work, else it does
| work.
| > |
| > | The scenario:
| > | After the initial page load, you enter data into controls and hit
submit
| > | button, the process is as follows:
| > | Page_Load
| > | DataList's OnLoad
| > | Composite Control's OnLoad
| > | Submit button's OnClick - At this point, the controls in the composite
| > | control have no listitems and no selectedValue properties.
| > |
| > | I have statically added the composite control onto the same page as
the
| > | dynamic one, so here is the process in this scenario:
| > | Page_Load
| > | Composite Control's OnLoad (The one whose parent is Page)
| > | DataList's OnLoad
| > | Composite Control's OnLoad (The one whose parent is the Custom
DataList)
| > | Submit button's OnClick - At this point, the controls in the
statically
| > | declared composite control have listitems and have values for
| > selectedValue
| > | properties.
| > |
| > | So the same control at the same time - the one outside the custom
| Datalist
| > | has its controls' state set up correctly, the ones inside does not.
| > |
| > | So the same reason is at play here. Maybe since i am dynamically
| creating
| > | the class using reflection (Assembly.CreateInstance()) that has
| something
| > to
| > | do with it?
| > |
| > | Please help mr. Cheng.
| > |
| > | Thank you very much!
| > |
| > | TS
| > |
| > |
| > |
| > | | > | > Hi TS,
| > | >
| > | > First, I'm glad that you've got your composite control work, all the
| > | > dropdownlist's postback events can fire correctly,yes?
| > | >
| > | > As for the new problem you encountered when adding your composite
| > control
| > | > into DataList's item, is the DataList the asp.net's buildin DataList
| > | > control? And since you mentioned that you dynamically add your
| control
| > | > into it, how do you dynamically add your custom control? Will there
| > occur
| > | > problem if you statically add your control into DataList?
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | > --------------------
| > | > | From: "TS" <[email protected]>
| > | > | References: <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <unRs#[email protected]>
| > | > <[email protected]>
| > | > | Subject: Re: explanation of when need to repopulate control
| > | > | Date: Wed, 3 Aug 2005 19:07:16 -0500
| > | > | Lines: 1153
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | > | Path:
| TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| > | > | X-Tomcat-NG:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > |
| > | > | Well Steve, I am almost done. My control works well, except its
not
| in
| > | the
| > | > | framework i just mentioned. Adding my control dynamically to the
| > | > datalist's
| > | > | item may be the root of the cause. i've made sure all custom
| controls
| > | > | implmenet INamingContainer & I think all controls have their id's
| set,
| > | so
| > | > | what else can i do?
| > | > |
| > | > | thanks a bunch
| > | > |
| > | > | | > | > | > I have figured the cause of the problem, sort of. My main
control
| > was
| > | > | being
| > | > | > loaded dynamically during a custom data list control's
| ItemDataBound
| > | > | event,
| > | > | > and then added to the e.item.controls collection. Once I removed
| it
| > | from
| > | > | > here, the correct event was called in my control. the problem
is i
| > | need
| > | > to
| > | > | > keep it where it is because of the way the page works.
| > | > | >
| > | > | > I tried to add INamingContainer to the custom Datalist, but that
| > | didn't
| > | > | > help. Any ideas what could make this happen?
| > | > | >
| > | > | > thanks so much, i know i'm being a pain, but i'm stuck!
| > | > | >
| > | > | > This is the custom DataLists' event:
| > | > | > protected override void OnItemDataBound(DataListItemEventArgs e)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > base.OnItemDataBound(e);
| > | > | >
| > | > | > Parameter parameter = (Parameter)e.Item.DataItem;
| > | > | >
| > | > | > try
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Control control;
| > | > | >
| > | > | > if(parameter.Type == ParameterType.Control)
| > | > | >
| > | > | > control = this.Page.LoadControl(parameter.ControlPath);
| > | > | >
| > | > | > else
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Assembly assembly = parameter.Assembly;
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > // The control didn't declare its own assembly, so use the
| report's
| > | > | > ControlsAssembly
| > | > | >
| > | > | > assembly = this.ControlsAssembly;
| > | > | >
| > | > | > // Ther report's ControlsAssembly is null, so use current page's
| > | > assembly
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > assembly = this.Page.GetType().BaseType.Assembly;
| > | > | >
| > | > | > }
| > | > | >
| > | > | >
| > | > | > control = (Control)
| > | assembly.CreateInstance(parameter.ControlTypeName);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > control.ID = parameter.Name;
| > | > | >
| > | > | > // Set up all the properties of this control from the
| > | > parameter.properties
| > | > | >
| > | > | > foreach(DictionaryEntry de in parameter.Properties)
| > | > | >
| > | > | > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| > | > | >
| > | > | >
| > | > | > e.Item.Controls.Add(control);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > catch (Exception ex)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > throw new ApplicationException("Unable to render criteria.
Reason:
| > " +
| > | > | > ex.Message, ex);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > }
| > | > | >
| > | > | > | > | > | > > In testing, i removed the main parent dropdown and only left
the
| 2
| > | > below
| > | > | > it.
| > | > | > > this time, the same scenario happened...when the child
dropdown
| > list
| > | > | > > autopostsback, it's immediate parent's selectedindexchanged
| event
| > | > fires!
| > | > | I
| > | > | > 'm
| > | > | > > starting to pull my hair out now...I"m stuck!
| > | > | > >
| > | > | > > please help superman
| > | > | > >
| > | > | > > | > | > | > > > Another problem:
| > | > | > > >
| > | > | > > > while i'm waiting on your remark to my last post, i removed
| the
| > | sub
| > | > | > > > composite controls from my composite control so that there
is
| > only
| > | > | drop
| > | > | > > down
| > | > | > > > lists on it. During CreateChildcontrols, i load the main
drop
| > down
| > | > | using
| > | > | > > > databind. When the page is sent to browser for the first
time,
| i
| > | > have
| > | > | my
| > | > | > > > main drop down filled. I then select an item and its
| > | > | > SelectedIndexChanged
| > | > | > > > fires and populates the send drop down list. Then when i
| select
| > an
| > | > | item
| > | > | > > from
| > | > | > > > it, it posts back, and the event that gets called is the
| > | main(first)
| > | > | > > > dropdown list's SelectedIndexChanged event, which then
| > | re-populates
| > | > | the
| > | > | > > > second drop down list, then the control returns to the
browser
| > | (The
| > | > | > > > SelectedIndexChanged event never fired for the 2nd
dropdown's
| > | > changed
| > | > | > > > event.???
| > | > | > > >
| > | > | > > > thanks again
| > | > | > > >
| > | > | > > > using System;
| > | > | > > >
| > | > | > > > using System.Collections.Specialized;
| > | > | > > >
| > | > | > > > using System.Web.UI;
| > | > | > > >
| > | > | > > > using System.Web.UI.WebControls;
| > | > | > > >
| > | > | > > > using System.Text;
| > | > | > > >
| > | > | > > > using OperationsTeams.Business;
| > | > | > > >
| > | > | > > > using OperationsTeams.Data;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting.WebControls;
| > | > | > > >
| > | > | > > > namespace OperationsTeams.Web.ReportControls
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > /// <summary>
| > | > | > > >
| > | > | > > > /// Summary description for FiscalAgentHierarchy.
| > | > | > > >
| > | > | > > > /// </summary>
| > | > | > > >
| > | > | > > > public class FiscalAgentHierarchy : WebControl,
| > | > | IReportParameterControl,
| > | > | > > > INamingContainer
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > protected override void OnLoad(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnLoad (e);
| > | > | > > >
| > | > | > > >
| > | > | > > > // The last state of controls from viewstate is now loaded
| > (Before
| > | > the
| > | > | > > > client data is processed)
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | > | > > > protected override void OnPreRender(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnPreRender (e);
| > | > | > > >
| > | > | > > > // The controls now have the client values from the the last
| > | > postback
| > | > | > > >
| > | > | > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > | > | > > >
| > | > | > > > // ddlProviders.Visible = ProviderVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Visible = SiteVisible;
| > | > | > > >
| > | > | > > > // ddlClasses.Visible = ClassVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > > // ddlSites.Visible = true;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > 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 ddlFundingSource_SelectedIndexChanged(object
| > sender,
| > | > | > > EventArgs
| > | > | > > > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlProviders_SelectedIndexChanged(object
sender,
| > | > | EventArgs
| > | > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlSites_SelectedIndexChanged(object sender,
| > | EventArgs
| > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > protected override void CreateChildControls()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > this.ddlFundingSource = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlProviders = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlSites = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlClasses = new DropDownList();
| > | > | > > >
| > | > | > > > ddlFundingSource.ID = FundingSourceControlId;
| > | > | > > >
| > | > | > > > ddlProviders.ID = ProvidersControlId;
| > | > | > > >
| > | > | > > > ddlSites.ID = SitesControlId;
| > | > | > > >
| > | > | > > > ddlClasses.ID = ClassesControlId;
| > | > | > > >
| > | > | > > >
| > | > | > > > LoadProviders();
| > | > | > > >
| > | > | > > > // start containing table
| > | > | > > >
| > | > | > > > this.Controls.Add(WebHelper.MakeLiteral("<table
cellpadding=0
| > | > | > > > cellspacing=0><tr><td>"));
| > | > | > > >
| > | > | > > >
| > | > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > | > > >
| > | > | > > > // 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( said:
| > | > | > > >
| > | > | > > > // 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( said:
| > | > | > > > );
| > | > | > > >
| > | > | > > > 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( said:
| > | > | > > >
| > | > | > > > this.Controls.Add(ddlClasses);
| > | > | > > >
| > | > | > > >
| this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > | > | > > >
| > | > | > > > // end containing table
| > | > | > > >
| > | > | > > >
| this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > | > | > > >
| > | > | > > > ddlFundingSource.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlProviders.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlSites.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlSites_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > | > | > > > ddlSites.AutoPostBack = true;
| > | > | > > >
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadFundingSource()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
| > 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = 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
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadProviders()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
1;//fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > >
| > | > | > > >
| > | > | > > > ProviderVisible = true;
| > | > | > > >
| > | > | > > > // are these dates correct???????????????????????????
| > | > | > > >
| > | > | > > > ddlProviders.DataSource =
| > FiscalAgentProvider.Find(fiscalAgentId,
| > | > new
| > | > | > > > DateTime(2005,7,1), new
| > | > | > > >
| > | > |
| > DateTime(2006,6,30));//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();
| > | > | > > >
| > | > | > > > ProviderVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadSites()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlProviders.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // Load the Site search parameters.
| > | > | > > >
| > | > | > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > | > | > > >
| > | > | > > > siteFindArgs.FiscalAgentId=1;
| > | > | > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > SiteVisible = 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();
| > | > | > > >
| > | > | > > > SiteVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadClasses()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlSites.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| > | > | AdultEdClassFindArgs();
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.FiscalAgentId =
| > | > | > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > | > | > > > rysReportingYearSelector.ReportingYearStartDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > | > | > > > rysReportingYearSelector.ReportingYearEndDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ProviderName =
| > ddlProviders.SelectedValue;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > | > | > > >
| > | > | > > >
| > | > | > > > ClassVisible = true;
| > | > | > > >
| > | > | > > > ddlClasses.DataSource =
| AdultEdClass.Find(adultEdClassFindArgs);
| > | > | > > >
| > | > | > > > ddlClasses.DataTextField = "Name";
| > | > | > > >
| > | > | > > > ddlClasses.DataValueField = "ClassId";
| > | > | > > >
| > | > | > > > ddlClasses.DataBind();
| > | > | > > >
| > | > | > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
| > | > string.Empty));
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > else
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > ddlClasses.Items.Clear();
| > | > | > > >
| > | > | > > > ClassVisible = 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
| > | > | > > >
| > | > | > > > protected bool FundingSourceVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["FundingSourceVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["FundingSourceVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["FundingSourceVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ProviderVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ProviderVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ProviderVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ProviderVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool SiteVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["SiteVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["SiteVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["SiteVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ClassVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ClassVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ClassVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ClassVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > #region Private Member Variables
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | message
| > | > | > > > | > | > | > > > > Hi TS,
| > | > | > > > >
| > | > | > > > > See you again :), seems you're rushing in a asp.net
project
| > | these
| > | > | > days?
| > | > | > > > > For the question you mentioned in this post, here are some
| of
| > my
| > | > | > > > > understanding and suggestions:
| > | > | > > > >
| > | > | > > > > 1. ASP.NET controls derived from Control will
automatically
| > | > maintain
| > | > | > its
| > | > | > > > > ViewStates according to the asp.net web page's events
| > sequence.
| > | So
| > | > | for
| > | > | > > > > composite control, those nested sub Controls' status
| > (properties
| > | > | which
| > | > | > > be
| > | > | > > > > persistd in Viewsstate ) will be store and retrieve
| > | automatically.
| > | > | > > > >
| > | > | > > > > 2. However, there're some thing we need to care when
| building
| > | > | > composite
| > | > | > > > > control:
| > | > | > > > > #remember to implement INamingContainer for controls which
| > will
| > | > have
| > | > | > > > nested
| > | > | > > > > sub controls. Otherwise, even handler mapping, ViewState
| > loading
| > | > | will
| > | > | > > > occur
| > | > | > > > > unexpectedly.
| > | > | > > > >
| > | > | > > > > #Do remember to assign a explicit ID for each sub
| > controls(same
| > | > | reason
| > | > | > > as
| > | > | > > > > #1). Also, please always try best to add subcontrols in
the
| > | > | > > > > "CreateChildControls" method(just create control
hierarchy)
| > and
| > | > put
| > | > | > > > > manipulating code in postback event or PreRender event.
| > | > | > > > >
| > | > | > > > > In addition, for your detaile scenario, I've just built a
| very
| > | > | simple
| > | > | > > demo
| > | > | > > > > control which have three dropdownlists and The "Top" one
| will
| > | > | display
| > | > | > > > > first(other twos invisible) and according to the top one's
| > | > | selection,
| > | > | > > the
| > | > | > > > > "Mid" dropdownlist will be pouplated and the same when the
| > | "mid"'s
| > | > | > > > > selection changed......
| > | > | > > > >
| > | > | > > > > Here's the control's code for your reference:
| > | > | > > > >
| > | > | > > > > =========================
| > | > | > > > > [DefaultProperty("Text"),
| > | > | > > > > ToolboxData("<{0}:MultiListControl
| > | > | > > runat=server></{0}:MultiListControl>")]
| > | > | > > > > public class MultiListControl :
| > | > | System.Web.UI.WebControls.WebControl,
| > | > | > > > > INamingContainer
| > | > | > > > > {
| > | > | > > > > private string text;
| > | > | > > > >
| > | > | > > > > private DropDownList lstTop;
| > | > | > > > > private DropDownList lstMid;
| > | > | > > > > private DropDownList lstBot;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected bool MidVisible
| > | > | > > > > {
| > | > | > > > > get{
| > | > | > > > > if(ViewState["MID_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["MID_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set{
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["MID_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > protected bool BotVisible
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > if(ViewState["BOT_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["BOT_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["BOT_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > [Bindable(true),
| > | > | > > > > Category("Appearance"),
| > | > | > > > > DefaultValue("")]
| > | > | > > > > public string Text
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > return text;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > text = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void CreateChildControls()
| > | > | > > > > {
| > | > | > > > > Controls.Clear();
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > <table width='100%'>
| > | > | > > > > <tr><td>
| > | > | > > > > "));
| > | > | > > > >
| > | > | > > > > lstTop = new DropDownList();
| > | > | > > > > lstTop.ID = "lstTop";
| > | > | > > > >
| > | > | > > > > lstTop.Items.Add("----------");
| > | > | > > > > lstTop.Items.Add("Top_Item_1");
| > | > | > > > > lstTop.Items.Add("Top_Item_2");
| > | > | > > > > lstTop.Items.Add("Top_Item_3");
| > | > | > > > > lstTop.Items.Add("Top_Item_4");
| > | > | > > > >
| > | > | > > > > Controls.Add(lstTop);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > > lstMid = new DropDownList();
| > | > | > > > > lstMid.ID = "lstMid";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstMid);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstBot = new DropDownList();
| > | > | > > > > lstBot.ID = "lstBot";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstBot);
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > </td></tr>
| > | > | > > > > </table>
| > | > | > > > > "
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstTop.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstMid.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstBot.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > >
| > | > | > > > > lstTop.AutoPostBack = lstMid.AutoPostBack =
| > lstBot.AutoPostBack
| > | =
| > | > | > true;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void OnPreRender(EventArgs e)
| > | > | > > > > {
| > | > | > > > > base.OnPreRender (e);
| > | > | > > > >
| > | > | > > > > lstMid.Visible = MidVisible;
| > | > | > > > > lstBot.Visible = BotVisible;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > private void lst_SelectedIndexChanged(object sender,
| > | > | System.EventArgs
| > | > | > e)
| > | > | > > > > {
| > | > | > > > >
| > | > | > > > > DropDownList lst = sender as DropDownList;
| > | > | > > > >
| > | > | > > > > switch(lst.ID)
| > | > | > > > > {
| > | > | > > > > case "lstTop":
| > | > | > > > >
| > | > | > > > > if(lst.SelectedIndex != 0)
| > | > | > > > > {
| > | > | > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstMid.DataTextField = "Text";
| > | > | > > > > lstMid.DataValueField= "Value";
| > | > | > > > > lstMid.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = true;
| > | > | > > > > }
| > | > | > > > > else
| > | > | > > > > {
| > | > | > > > > MidVisible = BotVisible = false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstMid":
| > | > | > > > >
| > | > | > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstBot.DataTextField = "Text";
| > | > | > > > > lstBot.DataValueField= "Value";
| > | > | > > > > lstBot.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = BotVisible = true;
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstBot":
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > Page.Response.Write("<br>" + lst.ID +
| > "_selectedindexchanged!" +
| > | > | > > > > lst.EnableViewState);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > #region --Helper functions---
| > | > | > > > >
| > | > | > > > > public ListItemCollection GetSubItems(string parent)
| > | > | > > > > {
| > | > | > > > > ListItemCollection items = new ListItemCollection();
| > | > | > > > > int count = parent.Length;
| > | > | > > > >
| > | > | > > > > for(int i=0;i<count;++i)
| > | > | > > > > {
| > | > | > > > > items.Add(parent + "_Item_" + i);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return items;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > #endregion
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > ========================
| > | > | > > > > Hope helps. Thanks,
| > | > | > > > >
| > | > | > > > > Steven Cheng
| > | > | > > > > Microsoft Online Support
| > | > | > > > >
| > | > | > > > > Get Secure! www.microsoft.com/security
| > | > | > > > > (This posting is provided "AS IS", with no warranties, and
| > | confers
| > | > | no
| > | > | > > > > rights.)
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > --------------------
| > | > | > > > > | From: "TS" <[email protected]>
| > | > | > > > > | References: <[email protected]>
| > | > | > > > > | Subject: Re: explanation of when need to repopulate
| control
| > | > | > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > | > | > > > > | Lines: 39
| > | > | > > > > | X-Priority: 3
| > | > | > > > > | X-MSMail-Priority: Normal
| > | > | > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | > > > > | Message-ID: <[email protected]>
| > | > | > > > > | Newsgroups:
| > | > | > > > >
| > | > | > > >
| > | > | > >
| > | > | >
| > | > |
| > | >
| > |
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > | > | > > > > framework.aspnet.buildingcontrols
| > | > | > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us
| 198.214.103.100
| > | > | > > > > | Path:
| > | > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | > | > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > | > > > >
| microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > | > | > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > | > | > > > > | X-Tomcat-NG:
| > | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | > > > > |
| > | > | > > > > | sorry, heres the scenario i'm trying to accomplish:
| > | > | > > > > | I have a composite control that contains 4 drop down
| lists.
| > | When
| > | > | the
| > | > | > > > page
| > | > | > > > > | loads initially, i want the first drop down filled and
the
| > | rest
| > | > | > > > invisible.
| > | > | > > > > | When you select an item in this ddl, it posts back to
the
| > | server
| > | > | and
| > | > | > > > based
| > | > | > > > > | on its value, it populates its immediate child's drop
down
| > | list.
| > | > | So
| > | > | > > now
| > | > | > > > > the
| > | > | > > > > | top ddl has a value selected and the 2nd one just has
its
| > | items
| > | > | > > > populated.
| > | > | > > > > | Then when the 2nd drop down list gets selected, it posts
| to
| > | the
| > | > | > server
| > | > | > > > and
| > | > | > > > > | its value is used to populate(filter) the items for the
| 3rd
| > | drop
| > | > | > down
| > | > | > > > > | list...and so on for each drop down list.
| > | > | > > > > |
| > | > | > > > > | Please tell me what i need to do to handle post back
data
| > and
| > | > | > maintain
| > | > | > > > > state
| > | > | > > > > | from one postback to another while keeping the drop
| > downlists
| > | > | filled
| > | > | > > and
| > | > | > > > > | their values persisted.
| > | > | > > > > |
| > | > | > > > > | thank you again!
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > | | > | > | > > > > | > I have a quesiton:
| > | > | > > > > | > if i have a composite control and on its intial page
| > | loading,
| > | > i
| > | > | > fill
| > | > | > > > my
| > | > | > > > > | (sub
| > | > | > > > > | > control) drop down list's items collection from the
| > database
| > | > and
| > | > | > > > return.
| > | > | > > > > | > When the user hits a button to cause postback, the
| control
| > | is
| > | > | > going
| > | > | > > to
| > | > | > > > > get
| > | > | > > > > | > initialized, then does its items collection that i
| filled
| > on
| > | > the
| > | > | > > > initial
| > | > | > > > > | > page request get repopulated from viewstate? And on
top
| of
| > | > that,
| > | > | > if
| > | > | > > > so,
| > | > | > > > > | does
| > | > | > > > > | > the list item that person selected in the drop down
list
| > | again
| > | > | set
| > | > | > > > > itself
| > | > | > > > > | as
| > | > | > > > > | > the selected item in the list?
| > | > | > > > > | >
| > | > | > > > > | > OR do i have to re-load the items on every page
request
| > and
| > | > then
| > | > | > > > > populate
| > | > | > > > > | > its value some other way???
| > | > | > > > > | >
| > | > | > > > > | > thanks a bunch
| > | > | > > > > | >
| > | > | > > > > | >
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > >
| > | > | > > >
| > | > | > > >
| > | > | > >
| > | > | > >
| > | > | >
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
T

TS

If i need to send it to you, can you recommend a good encryption strategy?

Steven Cheng said:
You're welcome TS.

Glad that you've overcome the problem.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "TS" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<unRs#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: explanation of when need to repopulate control
| Date: Mon, 8 Aug 2005 12:50:32 -0500
| Lines: 1445
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4014
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Well you were right that it had something to do with the custom control.
The
| datalist was trying to load itself during page load. i put the code in
Init,
| and it worked.
|
| thanks steven
|
| | > Thanks for your followup TS.
| >
| > So can I say that currently your custom webcontrol(not template list
| > control) can correctly be added both statically and dynamically in the
| > normal DataList or Repeater controls (asp.net buildin ) , but have some
| > problem for postback events when added in your custom list control?
| >
| > If so, we should keep focus on the custom datalist control. Has it any
| > problems when we nest some asp.net buildin controls in it? Would you try
| > making a simplified version of your custom datalist control so that we
can
| > have a view to see whether there is anything wrong in it. Also, it'll be
| > helpful you also provide the complete code that you dynamically add
| control
| > into the datalist (through reflection).
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "TS" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <unRs#[email protected]>
| > <[email protected]>
| > <#[email protected]>
| > <[email protected]>
| > | Subject: Re: explanation of when need to repopulate control
| > | Date: Fri, 5 Aug 2005 17:19:23 -0500
| > | Lines: 1298
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:4003
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | I have a new problem now. I have figured out that the cause is the
same
| > | reason. If its in the custom DataList, it doesn't work, else it does
| work.
| > |
| > | The scenario:
| > | After the initial page load, you enter data into controls and hit
submit
| > | button, the process is as follows:
| > | Page_Load
| > | DataList's OnLoad
| > | Composite Control's OnLoad
| > | Submit button's OnClick - At this point, the controls in the composite
| > | control have no listitems and no selectedValue properties.
| > |
| > | I have statically added the composite control onto the same page as
the
| > | dynamic one, so here is the process in this scenario:
| > | Page_Load
| > | Composite Control's OnLoad (The one whose parent is Page)
| > | DataList's OnLoad
| > | Composite Control's OnLoad (The one whose parent is the Custom
DataList)
| > | Submit button's OnClick - At this point, the controls in the
statically
| > | declared composite control have listitems and have values for
| > selectedValue
| > | properties.
| > |
| > | So the same control at the same time - the one outside the custom
| Datalist
| > | has its controls' state set up correctly, the ones inside does not.
| > |
| > | So the same reason is at play here. Maybe since i am dynamically
| creating
| > | the class using reflection (Assembly.CreateInstance()) that has
| something
| > to
| > | do with it?
| > |
| > | Please help mr. Cheng.
| > |
| > | Thank you very much!
| > |
| > | TS
| > |
| > |
| > |
| > | | > | > Hi TS,
| > | >
| > | > First, I'm glad that you've got your composite control work, all the
| > | > dropdownlist's postback events can fire correctly,yes?
| > | >
| > | > As for the new problem you encountered when adding your composite
| > control
| > | > into DataList's item, is the DataList the asp.net's buildin DataList
| > | > control? And since you mentioned that you dynamically add your
| control
| > | > into it, how do you dynamically add your custom control? Will there
| > occur
| > | > problem if you statically add your control into DataList?
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | > --------------------
| > | > | From: "TS" <[email protected]>
| > | > | References: <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > <unRs#[email protected]>
| > | > <[email protected]>
| > | > | Subject: Re: explanation of when need to repopulate control
| > | > | Date: Wed, 3 Aug 2005 19:07:16 -0500
| > | > | Lines: 1153
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | > | Path:
| TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3989
| > | > | X-Tomcat-NG:
| microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > |
| > | > | Well Steve, I am almost done. My control works well, except its
not
| in
| > | the
| > | > | framework i just mentioned. Adding my control dynamically to the
| > | > datalist's
| > | > | item may be the root of the cause. i've made sure all custom
| controls
| > | > | implmenet INamingContainer & I think all controls have their id's
| set,
| > | so
| > | > | what else can i do?
| > | > |
| > | > | thanks a bunch
| > | > |
| > | > | | > | > | > I have figured the cause of the problem, sort of. My main
control
| > was
| > | > | being
| > | > | > loaded dynamically during a custom data list control's
| ItemDataBound
| > | > | event,
| > | > | > and then added to the e.item.controls collection. Once I removed
| it
| > | from
| > | > | > here, the correct event was called in my control. the problem
is i
| > | need
| > | > to
| > | > | > keep it where it is because of the way the page works.
| > | > | >
| > | > | > I tried to add INamingContainer to the custom Datalist, but that
| > | didn't
| > | > | > help. Any ideas what could make this happen?
| > | > | >
| > | > | > thanks so much, i know i'm being a pain, but i'm stuck!
| > | > | >
| > | > | > This is the custom DataLists' event:
| > | > | > protected override void OnItemDataBound(DataListItemEventArgs e)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > base.OnItemDataBound(e);
| > | > | >
| > | > | > Parameter parameter = (Parameter)e.Item.DataItem;
| > | > | >
| > | > | > try
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Control control;
| > | > | >
| > | > | > if(parameter.Type == ParameterType.Control)
| > | > | >
| > | > | > control = this.Page.LoadControl(parameter.ControlPath);
| > | > | >
| > | > | > else
| > | > | >
| > | > | > {
| > | > | >
| > | > | > Assembly assembly = parameter.Assembly;
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > // The control didn't declare its own assembly, so use the
| report's
| > | > | > ControlsAssembly
| > | > | >
| > | > | > assembly = this.ControlsAssembly;
| > | > | >
| > | > | > // Ther report's ControlsAssembly is null, so use current page's
| > | > assembly
| > | > | >
| > | > | > if(assembly == null)
| > | > | >
| > | > | > assembly = this.Page.GetType().BaseType.Assembly;
| > | > | >
| > | > | > }
| > | > | >
| > | > | >
| > | > | > control = (Control)
| > | assembly.CreateInstance(parameter.ControlTypeName);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > control.ID = parameter.Name;
| > | > | >
| > | > | > // Set up all the properties of this control from the
| > | > parameter.properties
| > | > | >
| > | > | > foreach(DictionaryEntry de in parameter.Properties)
| > | > | >
| > | > | > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| > | > | >
| > | > | >
| > | > | > e.Item.Controls.Add(control);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > catch (Exception ex)
| > | > | >
| > | > | > {
| > | > | >
| > | > | > throw new ApplicationException("Unable to render criteria.
Reason:
| > " +
| > | > | > ex.Message, ex);
| > | > | >
| > | > | > }
| > | > | >
| > | > | > }
| > | > | >
| > | > | > | > | > | > > In testing, i removed the main parent dropdown and only left
the
| 2
| > | > below
| > | > | > it.
| > | > | > > this time, the same scenario happened...when the child
dropdown
| > list
| > | > | > > autopostsback, it's immediate parent's selectedindexchanged
| event
| > | > fires!
| > | > | I
| > | > | > 'm
| > | > | > > starting to pull my hair out now...I"m stuck!
| > | > | > >
| > | > | > > please help superman
| > | > | > >
| > | > | > > | > | > | > > > Another problem:
| > | > | > > >
| > | > | > > > while i'm waiting on your remark to my last post, i removed
| the
| > | sub
| > | > | > > > composite controls from my composite control so that there
is
| > only
| > | > | drop
| > | > | > > down
| > | > | > > > lists on it. During CreateChildcontrols, i load the main
drop
| > down
| > | > | using
| > | > | > > > databind. When the page is sent to browser for the first
time,
| i
| > | > have
| > | > | my
| > | > | > > > main drop down filled. I then select an item and its
| > | > | > SelectedIndexChanged
| > | > | > > > fires and populates the send drop down list. Then when i
| select
| > an
| > | > | item
| > | > | > > from
| > | > | > > > it, it posts back, and the event that gets called is the
| > | main(first)
| > | > | > > > dropdown list's SelectedIndexChanged event, which then
| > | re-populates
| > | > | the
| > | > | > > > second drop down list, then the control returns to the
browser
| > | (The
| > | > | > > > SelectedIndexChanged event never fired for the 2nd
dropdown's
| > | > changed
| > | > | > > > event.???
| > | > | > > >
| > | > | > > > thanks again
| > | > | > > >
| > | > | > > > using System;
| > | > | > > >
| > | > | > > > using System.Collections.Specialized;
| > | > | > > >
| > | > | > > > using System.Web.UI;
| > | > | > > >
| > | > | > > > using System.Web.UI.WebControls;
| > | > | > > >
| > | > | > > > using System.Text;
| > | > | > > >
| > | > | > > > using OperationsTeams.Business;
| > | > | > > >
| > | > | > > > using OperationsTeams.Data;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting;
| > | > | > > >
| > | > | > > > using OperationsTeams.Reporting.WebControls;
| > | > | > > >
| > | > | > > > namespace OperationsTeams.Web.ReportControls
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > /// <summary>
| > | > | > > >
| > | > | > > > /// Summary description for FiscalAgentHierarchy.
| > | > | > > >
| > | > | > > > /// </summary>
| > | > | > > >
| > | > | > > > public class FiscalAgentHierarchy : WebControl,
| > | > | IReportParameterControl,
| > | > | > > > INamingContainer
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > protected override void OnLoad(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnLoad (e);
| > | > | > > >
| > | > | > > >
| > | > | > > > // The last state of controls from viewstate is now loaded
| > (Before
| > | > the
| > | > | > > > client data is processed)
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | > | > > > protected override void OnPreRender(EventArgs e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > base.OnPreRender (e);
| > | > | > > >
| > | > | > > > // The controls now have the client values from the the last
| > | > postback
| > | > | > > >
| > | > | > > > // ddlFundingSource.Visible = FundingSourceVisible;
| > | > | > > >
| > | > | > > > // ddlProviders.Visible = ProviderVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Visible = SiteVisible;
| > | > | > > >
| > | > | > > > // ddlClasses.Visible = ClassVisible;
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > > // ddlSites.Visible = true;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > 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 ddlFundingSource_SelectedIndexChanged(object
| > sender,
| > | > | > > EventArgs
| > | > | > > > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlProviders_SelectedIndexChanged(object
sender,
| > | > | EventArgs
| > | > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void ddlSites_SelectedIndexChanged(object sender,
| > | EventArgs
| > | > e)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > protected override void CreateChildControls()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > this.ddlFundingSource = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlProviders = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlSites = new DropDownList();
| > | > | > > >
| > | > | > > > this.ddlClasses = new DropDownList();
| > | > | > > >
| > | > | > > > ddlFundingSource.ID = FundingSourceControlId;
| > | > | > > >
| > | > | > > > ddlProviders.ID = ProvidersControlId;
| > | > | > > >
| > | > | > > > ddlSites.ID = SitesControlId;
| > | > | > > >
| > | > | > > > ddlClasses.ID = ClassesControlId;
| > | > | > > >
| > | > | > > >
| > | > | > > > LoadProviders();
| > | > | > > >
| > | > | > > > // start containing table
| > | > | > > >
| > | > | > > > this.Controls.Add(WebHelper.MakeLiteral("<table
cellpadding=0
| > | > | > > > cellspacing=0><tr><td>"));
| > | > | > > >
| > | > | > > >
| > | > | > > >
this.Controls.Add(WebHelper.MakeLiteral( said:
| > | > | > > >
| > | > | > > > // 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( said:
| > | > | > > >
| > | > | > > > // 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( said:
| > | > | > > > );
| > | > | > > >
| > | > | > > > 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( said:
| > | > | > > >
| > | > | > > > this.Controls.Add(ddlClasses);
| > | > | > > >
| > | > | > > >
| this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > | > | > > >
| > | > | > > > // end containing table
| > | > | > > >
| > | > | > > >
| this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));
| > | > | > > >
| > | > | > > > ddlFundingSource.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlFundingSource_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlProviders.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlProviders_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlSites.SelectedIndexChanged += new
| > | > | > > > EventHandler(ddlSites_SelectedIndexChanged);
| > | > | > > >
| > | > | > > > ddlFundingSource.AutoPostBack = ddlProviders.AutoPostBack =
| > | > | > > > ddlSites.AutoPostBack = true;
| > | > | > > >
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadFundingSource()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
| > 1;//this.fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = 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
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > FundingSourceVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadProviders()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > int fiscalAgentId =
1;//fasFiscalAgent.SelectedFiscalAgentId;
| > | > | > > >
| > | > | > > > if(fiscalAgentId != int.MinValue)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("help","1"));
| > | > | > > >
| > | > | > > > // ddlSites.Items.Add(new ListItem("me","2"));
| > | > | > > >
| > | > | > > >
| > | > | > > >
| > | > | > > > ProviderVisible = true;
| > | > | > > >
| > | > | > > > // are these dates correct???????????????????????????
| > | > | > > >
| > | > | > > > ddlProviders.DataSource =
| > FiscalAgentProvider.Find(fiscalAgentId,
| > | > new
| > | > | > > > DateTime(2005,7,1), new
| > | > | > > >
| > | > |
| > DateTime(2006,6,30));//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();
| > | > | > > >
| > | > | > > > ProviderVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadSites();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadSites()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlProviders.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > // Load the Site search parameters.
| > | > | > > >
| > | > | > > > SiteFindArgs siteFindArgs=new SiteFindArgs();
| > | > | > > >
| > | > | > > > siteFindArgs.FiscalAgentId=1;
| > | > | > > > //Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > SiteVisible = 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();
| > | > | > > >
| > | > | > > > SiteVisible = false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > // LoadClasses();
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > private void LoadClasses()
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ddlSites.SelectedValue != string.Empty)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > AdultEdClassFindArgs adultEdClassFindArgs = new
| > | > | AdultEdClassFindArgs();
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.FiscalAgentId =
| > | > | > > > Convert.ToInt32(fasFiscalAgent.SelectedFiscalAgentId);
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearStartDate =
| > | > | > > > rysReportingYearSelector.ReportingYearStartDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ReportingYearEndDate =
| > | > | > > > rysReportingYearSelector.ReportingYearEndDate;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.ProviderName =
| > ddlProviders.SelectedValue;
| > | > | > > >
| > | > | > > > // adultEdClassFindArgs.SiteName = ddlSites.SelectedValue;
| > | > | > > >
| > | > | > > >
| > | > | > > > ClassVisible = true;
| > | > | > > >
| > | > | > > > ddlClasses.DataSource =
| AdultEdClass.Find(adultEdClassFindArgs);
| > | > | > > >
| > | > | > > > ddlClasses.DataTextField = "Name";
| > | > | > > >
| > | > | > > > ddlClasses.DataValueField = "ClassId";
| > | > | > > >
| > | > | > > > ddlClasses.DataBind();
| > | > | > > >
| > | > | > > > ddlClasses.Items.Insert(0, new ListItem(string.Empty,
| > | > string.Empty));
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > else
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > ddlClasses.Items.Clear();
| > | > | > > >
| > | > | > > > ClassVisible = 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
| > | > | > > >
| > | > | > > > protected bool FundingSourceVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["FundingSourceVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["FundingSourceVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["FundingSourceVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ProviderVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ProviderVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ProviderVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ProviderVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool SiteVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["SiteVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["SiteVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["SiteVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > protected bool ClassVisible
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > get
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > if(ViewState["ClassVisible"] == null)
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > return false;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > return (bool)ViewState["ClassVisible"];
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > set
| > | > | > > >
| > | > | > > > {
| > | > | > > >
| > | > | > > > TrackViewState();
| > | > | > > >
| > | > | > > > ViewState["ClassVisible"] = value;
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > #endregion
| > | > | > > >
| > | > | > > > #region Private Member Variables
| > | > | > > >
| > | > | > > > 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
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > > }
| > | > | > > >
| > | > | > > >
| > | message
| > | > | > > > | > | > | > > > > Hi TS,
| > | > | > > > >
| > | > | > > > > See you again :), seems you're rushing in a asp.net
project
| > | these
| > | > | > days?
| > | > | > > > > For the question you mentioned in this post, here are some
| of
| > my
| > | > | > > > > understanding and suggestions:
| > | > | > > > >
| > | > | > > > > 1. ASP.NET controls derived from Control will
automatically
| > | > maintain
| > | > | > its
| > | > | > > > > ViewStates according to the asp.net web page's events
| > sequence.
| > | So
| > | > | for
| > | > | > > > > composite control, those nested sub Controls' status
| > (properties
| > | > | which
| > | > | > > be
| > | > | > > > > persistd in Viewsstate ) will be store and retrieve
| > | automatically.
| > | > | > > > >
| > | > | > > > > 2. However, there're some thing we need to care when
| building
| > | > | > composite
| > | > | > > > > control:
| > | > | > > > > #remember to implement INamingContainer for controls which
| > will
| > | > have
| > | > | > > > nested
| > | > | > > > > sub controls. Otherwise, even handler mapping, ViewState
| > loading
| > | > | will
| > | > | > > > occur
| > | > | > > > > unexpectedly.
| > | > | > > > >
| > | > | > > > > #Do remember to assign a explicit ID for each sub
| > controls(same
| > | > | reason
| > | > | > > as
| > | > | > > > > #1). Also, please always try best to add subcontrols in
the
| > | > | > > > > "CreateChildControls" method(just create control
hierarchy)
| > and
| > | > put
| > | > | > > > > manipulating code in postback event or PreRender event.
| > | > | > > > >
| > | > | > > > > In addition, for your detaile scenario, I've just built a
| very
| > | > | simple
| > | > | > > demo
| > | > | > > > > control which have three dropdownlists and The "Top" one
| will
| > | > | display
| > | > | > > > > first(other twos invisible) and according to the top one's
| > | > | selection,
| > | > | > > the
| > | > | > > > > "Mid" dropdownlist will be pouplated and the same when the
| > | "mid"'s
| > | > | > > > > selection changed......
| > | > | > > > >
| > | > | > > > > Here's the control's code for your reference:
| > | > | > > > >
| > | > | > > > > =========================
| > | > | > > > > [DefaultProperty("Text"),
| > | > | > > > > ToolboxData("<{0}:MultiListControl
| > | > | > > runat=server></{0}:MultiListControl>")]
| > | > | > > > > public class MultiListControl :
| > | > | System.Web.UI.WebControls.WebControl,
| > | > | > > > > INamingContainer
| > | > | > > > > {
| > | > | > > > > private string text;
| > | > | > > > >
| > | > | > > > > private DropDownList lstTop;
| > | > | > > > > private DropDownList lstMid;
| > | > | > > > > private DropDownList lstBot;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected bool MidVisible
| > | > | > > > > {
| > | > | > > > > get{
| > | > | > > > > if(ViewState["MID_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["MID_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set{
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["MID_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > protected bool BotVisible
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > if(ViewState["BOT_VISIBLE"] == null)
| > | > | > > > > {
| > | > | > > > > return false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return (bool)ViewState["BOT_VISIBLE"];
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > TrackViewState();
| > | > | > > > > ViewState["BOT_VISIBLE"] = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > [Bindable(true),
| > | > | > > > > Category("Appearance"),
| > | > | > > > > DefaultValue("")]
| > | > | > > > > public string Text
| > | > | > > > > {
| > | > | > > > > get
| > | > | > > > > {
| > | > | > > > > return text;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > set
| > | > | > > > > {
| > | > | > > > > text = value;
| > | > | > > > > }
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void CreateChildControls()
| > | > | > > > > {
| > | > | > > > > Controls.Clear();
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > <table width='100%'>
| > | > | > > > > <tr><td>
| > | > | > > > > "));
| > | > | > > > >
| > | > | > > > > lstTop = new DropDownList();
| > | > | > > > > lstTop.ID = "lstTop";
| > | > | > > > >
| > | > | > > > > lstTop.Items.Add("----------");
| > | > | > > > > lstTop.Items.Add("Top_Item_1");
| > | > | > > > > lstTop.Items.Add("Top_Item_2");
| > | > | > > > > lstTop.Items.Add("Top_Item_3");
| > | > | > > > > lstTop.Items.Add("Top_Item_4");
| > | > | > > > >
| > | > | > > > > Controls.Add(lstTop);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > > lstMid = new DropDownList();
| > | > | > > > > lstMid.ID = "lstMid";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstMid);
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"<br/>"
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstBot = new DropDownList();
| > | > | > > > > lstBot.ID = "lstBot";
| > | > | > > > >
| > | > | > > > > Controls.Add(lstBot);
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > Controls.Add(
| > | > | > > > > new LiteralControl(
| > | > | > > > > @"
| > | > | > > > > </td></tr>
| > | > | > > > > </table>
| > | > | > > > > "
| > | > | > > > > ));
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > lstTop.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstMid.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > > lstBot.SelectedIndexChanged +=new
| > | > | > > EventHandler(lst_SelectedIndexChanged);
| > | > | > > > >
| > | > | > > > > lstTop.AutoPostBack = lstMid.AutoPostBack =
| > lstBot.AutoPostBack
| > | =
| > | > | > true;
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > protected override void OnPreRender(EventArgs e)
| > | > | > > > > {
| > | > | > > > > base.OnPreRender (e);
| > | > | > > > >
| > | > | > > > > lstMid.Visible = MidVisible;
| > | > | > > > > lstBot.Visible = BotVisible;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > private void lst_SelectedIndexChanged(object sender,
| > | > | System.EventArgs
| > | > | > e)
| > | > | > > > > {
| > | > | > > > >
| > | > | > > > > DropDownList lst = sender as DropDownList;
| > | > | > > > >
| > | > | > > > > switch(lst.ID)
| > | > | > > > > {
| > | > | > > > > case "lstTop":
| > | > | > > > >
| > | > | > > > > if(lst.SelectedIndex != 0)
| > | > | > > > > {
| > | > | > > > > lstMid.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstMid.DataTextField = "Text";
| > | > | > > > > lstMid.DataValueField= "Value";
| > | > | > > > > lstMid.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = true;
| > | > | > > > > }
| > | > | > > > > else
| > | > | > > > > {
| > | > | > > > > MidVisible = BotVisible = false;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstMid":
| > | > | > > > >
| > | > | > > > > lstBot.DataSource = GetSubItems(lst.SelectedValue);
| > | > | > > > > lstBot.DataTextField = "Text";
| > | > | > > > > lstBot.DataValueField= "Value";
| > | > | > > > > lstBot.DataBind();
| > | > | > > > >
| > | > | > > > > MidVisible = BotVisible = true;
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > case "lstBot":
| > | > | > > > >
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > break;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > Page.Response.Write("<br>" + lst.ID +
| > "_selectedindexchanged!" +
| > | > | > > > > lst.EnableViewState);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > #region --Helper functions---
| > | > | > > > >
| > | > | > > > > public ListItemCollection GetSubItems(string parent)
| > | > | > > > > {
| > | > | > > > > ListItemCollection items = new ListItemCollection();
| > | > | > > > > int count = parent.Length;
| > | > | > > > >
| > | > | > > > > for(int i=0;i<count;++i)
| > | > | > > > > {
| > | > | > > > > items.Add(parent + "_Item_" + i);
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > return items;
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > #endregion
| > | > | > > > > }
| > | > | > > > >
| > | > | > > > > ========================
| > | > | > > > > Hope helps. Thanks,
| > | > | > > > >
| > | > | > > > > Steven Cheng
| > | > | > > > > Microsoft Online Support
| > | > | > > > >
| > | > | > > > > Get Secure! www.microsoft.com/security
| > | > | > > > > (This posting is provided "AS IS", with no warranties, and
| > | confers
| > | > | no
| > | > | > > > > rights.)
| > | > | > > > >
| > | > | > > > >
| > | > | > > > > --------------------
| > | > | > > > > | From: "TS" <[email protected]>
| > | > | > > > > | References: <[email protected]>
| > | > | > > > > | Subject: Re: explanation of when need to repopulate
| control
| > | > | > > > > | Date: Tue, 2 Aug 2005 18:32:23 -0500
| > | > | > > > > | Lines: 39
| > | > | > > > > | X-Priority: 3
| > | > | > > > > | X-MSMail-Priority: Normal
| > | > | > > > > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | > > > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | > > > > | Message-ID: <[email protected]>
| > | > | > > > > | Newsgroups:
| > | > | > > > >
| > | > | > > >
| > | > | > >
| > | > | >
| > | > |
| > | >
| > |
| >
|
microsoft.public.dotnet.framework.aspnet.webcontrols,microsoft.public.dotnet
| > | > | > > > > framework.aspnet.buildingcontrols
| > | > | > > > > | NNTP-Posting-Host: 103nat100.tea.state.tx.us
| 198.214.103.100
| > | > | > > > > | Path:
| > | > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | > | > > > > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > | > > > >
| microsoft.public.dotnet.framework.aspnet.buildingcontrols:3979
| > | > | > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:10243
| > | > | > > > > | X-Tomcat-NG:
| > | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > | > | > > > > |
| > | > | > > > > | sorry, heres the scenario i'm trying to accomplish:
| > | > | > > > > | I have a composite control that contains 4 drop down
| lists.
| > | When
| > | > | the
| > | > | > > > page
| > | > | > > > > | loads initially, i want the first drop down filled and
the
| > | rest
| > | > | > > > invisible.
| > | > | > > > > | When you select an item in this ddl, it posts back to
the
| > | server
| > | > | and
| > | > | > > > based
| > | > | > > > > | on its value, it populates its immediate child's drop
down
| > | list.
| > | > | So
| > | > | > > now
| > | > | > > > > the
| > | > | > > > > | top ddl has a value selected and the 2nd one just has
its
| > | items
| > | > | > > > populated.
| > | > | > > > > | Then when the 2nd drop down list gets selected, it posts
| to
| > | the
| > | > | > server
| > | > | > > > and
| > | > | > > > > | its value is used to populate(filter) the items for the
| 3rd
| > | drop
| > | > | > down
| > | > | > > > > | list...and so on for each drop down list.
| > | > | > > > > |
| > | > | > > > > | Please tell me what i need to do to handle post back
data
| > and
| > | > | > maintain
| > | > | > > > > state
| > | > | > > > > | from one postback to another while keeping the drop
| > downlists
| > | > | filled
| > | > | > > and
| > | > | > > > > | their values persisted.
| > | > | > > > > |
| > | > | > > > > | thank you again!
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > | | > | > | > > > > | > I have a quesiton:
| > | > | > > > > | > if i have a composite control and on its intial page
| > | loading,
| > | > i
| > | > | > fill
| > | > | > > > my
| > | > | > > > > | (sub
| > | > | > > > > | > control) drop down list's items collection from the
| > database
| > | > and
| > | > | > > > return.
| > | > | > > > > | > When the user hits a button to cause postback, the
| control
| > | is
| > | > | > going
| > | > | > > to
| > | > | > > > > get
| > | > | > > > > | > initialized, then does its items collection that i
| filled
| > on
| > | > the
| > | > | > > > initial
| > | > | > > > > | > page request get repopulated from viewstate? And on
top
| of
| > | > that,
| > | > | > if
| > | > | > > > so,
| > | > | > > > > | does
| > | > | > > > > | > the list item that person selected in the drop down
list
| > | again
| > | > | set
| > | > | > > > > itself
| > | > | > > > > | as
| > | > | > > > > | > the selected item in the list?
| > | > | > > > > | >
| > | > | > > > > | > OR do i have to re-load the items on every page
request
| > and
| > | > then
| > | > | > > > > populate
| > | > | > > > > | > its value some other way???
| > | > | > > > > | >
| > | > | > > > > | > thanks a bunch
| > | > | > > > > | >
| > | > | > > > > | >
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > > |
| > | > | > > > >
| > | > | > > >
| > | > | > > >
| > | > | > >
| > | > | > >
| > | > | >
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top