Nested CompositeControls and page lifecycle

Discussion in 'ASP .Net Building Controls' started by jazzMan007, Nov 14, 2005.

  1. jazzMan007

    jazzMan007 Guest

    Hey All -

    I'm working on a web site based on ASP.NET 2.0. Most of our major
    controls are based off a copy of CompositeControl (we have a base
    webcontrol class, and instead of putting all the base code into a
    basecompositecontrol, I just used reflector to create a
    CompositeControl that inherits from our base webcontrol class). We use
    master pages for the whole site, which provide a header, navigation,
    and main content area. In the content area is simply 1 composite
    control, which then has any number of nested composite controls in it.
    The CompositeControls are creating their UI by calling
    Page.LoadControl(PathToAscxFile) in CreateChildControls, which is in
    the base compositecontrol class, which then calls an abstract method
    that is handled in the inheriting class to find and wireup the

    The problem we're running into is trying to determine the lifecycle of
    the controls. For instance, in OnLoad of one of the root controls, I
    fetch data, call my overridden DataBind() to bind the data to the
    controls. The first line in Databind is base.DataBind() since that
    inherintly calls EnsureChildControls(), theoretically guaranteeing that
    the controls are valid before I bind to them. Seemed like a good
    pattern, however if any child control is designed using the same
    pattern (fetch data in OnLoad, call DataBind() to ensure controls & set
    their properties), their OnLoad is skipped because the base.DataBind()
    in the parent made a call to DataBindChildren, so I'm hitting
    DataBind() in the child control before it's OnLoad has run.

    >From what I've read online, when using CompositeControls, you can not

    guarantee when CreateChildControls is called, hence, you can't really
    use the OnInit or OnLoad events to load data. Additionally, having
    OnLoads skipped alltogether is pretty troubling. Should the entire
    wireup of the control be based on CreateChildControls and nothing at
    all in OnLoad/OnInit? Would it be a poor design to, say, explicitly
    call EnsureChildControls early in the lifecycle (since setting some
    properties could cause ChildControlsCreated to go back to false)? Or
    does everything have to happen within the scope of CreateChildControls?
    Can the rest of the page lifecycle be reliably used for anything?

    Thanks in advance,
    jazzMan007, Nov 14, 2005
    1. Advertisements

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. =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=

    CompositeControls: ViewState properties w/ Mapped properties probl

    =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=, Jan 19, 2006, in forum: ASP .Net
    Steven Cheng[MSFT]
    Jan 19, 2006
  2. Jeronimo Bertran

    CompositeControls not added to the toolbox

    Jeronimo Bertran, Apr 5, 2006, in forum: ASP .Net
    Steven Cheng[MSFT]
    Apr 14, 2006
  3. Sky Sigal

    Immediate v. Delayed Delegation of Properties in CompositeControls

    Sky Sigal, Jun 29, 2005, in forum: ASP .Net Building Controls
    Sky Sigal
    Jul 1, 2005
  4. Gery D. Dorazio

    Recommended practices for CompositeControls?

    Gery D. Dorazio, Feb 28, 2007, in forum: ASP .Net Building Controls
    Gery D. Dorazio
    Feb 28, 2007
  5. jeljeljel

    CompositeControls and RecreateChildControls()

    jeljeljel, Sep 20, 2007, in forum: ASP .Net Building Controls
    Nathan Sokalski
    Sep 28, 2007

Share This Page