Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Control with Complex Types and Inner Controls

Reply
Thread Tools

Control with Complex Types and Inner Controls

 
 
Bart Fibrich
Guest
Posts: n/a
 
      07-14-2004
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating custom controls out of more complex control types (eg change password control) ryan.d.rembaum@kp.org ASP .Net Building Controls 0 02-14-2007 01:25 AM
failing to instantiate an inner class because of order of inner classes Pyenos Python 2 12-27-2006 11:19 PM
Can XSD simple types be derived from complex types? Soren Kuula XML 2 12-01-2005 07:51 PM
State not preserved in inner controls of ASCX control Oleg Ogurok ASP .Net 1 06-23-2004 06:41 PM
inner classes in python as inner classes in Java Carlo v. Dango Python 14 10-19-2003 08:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57