explanation of when need to repopulate control

Discussion in 'ASP .Net Web Controls' started by TS, Aug 2, 2005.

  1. TS

    TS Guest

    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
    TS, Aug 2, 2005
    #1
    1. Advertising

  2. TS

    TS Guest

    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

    }

    }



    "TS" <> wrote in message
    news:...
    > 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
    >
    >
    TS, Aug 2, 2005
    #2
    1. Advertising

  3. TS

    TS Guest

    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!


    "TS" <> wrote in message
    news:...
    > 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
    >
    >
    TS, Aug 3, 2005
    #3
  4. Hi TS,

    Thanks for your posting. Regarding on this issue, I've posted my response
    in your another thread in the
    microsoft.public.dotnet.framework.aspnet.buildingcontrols newsgroup

    If you feel it convenient that we continue to discuss there, please feel
    free to post there.

    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" <>
    | References: <>
    | 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: <>
    | 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.webcontrols
    |
    | 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!
    |
    |
    | "TS" <> wrote in message
    | news:...
    | > 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
    | >
    | >
    |
    |
    |
    Steven Cheng[MSFT], Aug 3, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TaeHo Yoo
    Replies:
    4
    Views:
    729
  2. luna_s

    popup repopulate

    luna_s, Mar 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    332
    Teemu Keiski
    Mar 6, 2004
  3. JN

    Repopulate TreeView

    JN, Jan 26, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,125
  4. TS

    explanation of when need to repopulate control

    TS, Aug 2, 2005, in forum: ASP .Net Building Controls
    Replies:
    28
    Views:
    524
    Steven Cheng[MSFT]
    Aug 24, 2005
  5. Bill Cohagan

    Can't repopulate DropdownList control during postback?

    Bill Cohagan, Sep 29, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    245
    Steven Cheng[MSFT]
    Sep 29, 2006
Loading...

Share This Page