How do I Nest content in a CompositeControl?

Last post 10-17-2006 10:54 AM by bytor. 2 replies.

Sort Posts:

  • How do I Nest content in a CompositeControl?

    09-11-2006, 12:54 PM
    • Member
      10 point Member
    • bytor
    • Member since 09-11-2006, 12:35 PM
    • Posts 2

    Hi,

    I'm developing my first CompositeControl that contains a handful of standard ASP.NET server controls, one of which is an asp:Panel. I'm trying to find out how I can nest content within the begin and end tags of my custom control in an aspx page so that it appears in the panel of my composite control. For example, I'd like the inner content shown below to appear inside the panel of my custom control:

          <cc1:Comp1 ID="comp1" runat="server" Header="I am the header!" Width="400px" Height="300px" Footer="I am the footer!">
            Name: <asp:TextBox id="Name" runat="server"/>
            <asp:CheckBox runat="server" id="rememberMe" Checked="true" Text="Remember me!" />
          </cc1:Comp1>

    I have overridden CreateChildControls as recomended to create my controls but all nested content seems to get appended onto the end of the control tree, so renders after the custom control. I've tried many things to solve this - the closest I got was to re-arrange the control tree inside OnPreRender but then couldn't get the events to work fully.

    I'm sure there is a straight forward solution to this! 

    Any help much appreciated.

  • Re: How do I Nest content in a CompositeControl?

    09-14-2006, 3:12 PM
    • Contributor
      2,093 point Contributor
    • subdigital
    • Member since 08-11-2004, 4:02 PM
    • Houston
    • Posts 444
    • ASPInsiders

    Yes, you're right there is a straight forward way to approach this problem.  The approach you are looking for lies in the ControlBuilder class.  I was going to go into detail here, but I found a good link for you instead.

     http://www.aspnetpro.com/newsletterarticle/2006/05/asp200605de_l/asp200605de_l.asp

    Ben Scheirman
    http://www.flux88.com

    ASP.NET MVP
    Certified ScrumMaster
    ASPInsider
    MCSD
  • Re: How do I Nest content in a CompositeControl?

    10-17-2006, 10:54 AM
    • Member
      10 point Member
    • bytor
    • Member since 09-11-2006, 12:35 PM
    • Posts 2

    Thanks Ben, that certainly is an interesting article.

    I've solved my immediate problem by writing a user control instead but ultimately I would like to use a server control once I am more up to speed with the technology...

Page 1 of 1 (3 items)