Control with Complex Types and Inner Controls

Discussion in 'ASP .Net Building Controls' started by Bart Fibrich, Jul 14, 2004.

  1. Bart Fibrich

    Bart Fibrich Guest

    Recently I needed to create a control that included both complex properties
    and an inner control. Couldn't find much on the net so here it is.

    [ParseChildren(true)]
    public class OuterControl: WebControl
    {
    // A property that hold the inner control. (wrapped up in a property)
    public InnerControl Control = new InnerControl();

    public ComplexProp ComplexProperty = new ComplexProperty();

    // Add the inner control to the outer control.
    protected override void RenderContents(HtmlTextWriter output)
    {
    this.Controls.Add(_control);
    base.RenderContents(output);
    }
    }

    [ParseChildren(false)]
    public class InnerControl: WebControl {}

    public class ComplexProp
    {
    // Some complex fields
    public int x;
    public int y;
    }

    Usage :

    <myPrefix:OuterControl runat="server">
    <ComplexProperty x="1" y="2"/>
    <Control>
    <asp:Label Runat="server">hello world!</asp:Label>
    </control>
    </myPrefix:OuterControl>

    If the complex property needs to be a collection of complex items then you need
    to create a typed collection for the items and prefix the items.

    <myPrefix:OuterControl runat="server">
    <ComplexPropertyTypedCollection>
    <myPrefix:ComplexProperty x="1" y="2"/>
    <myPrefix:ComplexProperty x="3" y="4"/>
    </ComplexPropertyTypedCollection>
    <Control>
    <asp:Label Runat="server">hello world!</asp:Label>
    </control>
    </myPrefix:OuterControl>
    Bart Fibrich, Jul 14, 2004
    #1
    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. news.amnet.net.au
    Replies:
    1
    Views:
    560
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. Soren Kuula
    Replies:
    2
    Views:
    546
    Henry S. Thompson
    Dec 1, 2005
  3. Carlo v. Dango
    Replies:
    14
    Views:
    1,018
    Alex Martelli
    Oct 19, 2003
  4. Pyenos
    Replies:
    2
    Views:
    379
    Pyenos
    Dec 27, 2006
  5. Replies:
    0
    Views:
    170
Loading...

Share This Page