mrblah
mrblah

Reputation: 103717

when creating a asp.net control, how do you enable child tags in the markup?

Say I want to create my own listing control, like a repeater.

How can I make it support my own custom tags, i.e. like:

<blah:MyRepeater ID="id1" runat="server">
<Blah property1="234324" />
<midTemplate>
</midTemplate>

</blah:MyRepeater>

Upvotes: 1

Views: 102

Answers (2)

Mike J
Mike J

Reputation: 1154

You need to take a look at the ParseChildren and PersistChildren attributes.

Setting ParseChlidren to true and PersistChildren to false will cause the processor to process the items and presist them as properties of the control.

Your control definition should look something like this:

[ParseChildren(true)] 
[PersistChildren(false)]
public class MyRepeater : Control
{
}

Upvotes: 1

HermanTheSheep
HermanTheSheep

Reputation: 183

If the property on your control is public, you can add it in your opening tag,

<blah:MyRepeater ID="id1" runat="server" property1="234324" >

Upvotes: 1

Related Questions