ASP.NET Templated User Controls - Limit child controls allowable within a templated control

J

JohnyStyles

I have a templated user control which looks like this:

-----------------------------------------------------------------
<uc:MyUserControl runat=server>
<TemplateProperty>

</TemplateProperty>
</uc:MyUserControl>
-----------------------------------------------------------------

Currently i can drop any html/web controls/user controls into
TemplateProperty. I then handle these inside of my user control, in
the PreRender, I do run:
_templateProperty.InstantiateIn(aPlaceHolderInsideUserControl);

This all works. Very nice, allows for great content encapsulation.

Now, what I would like to do next is limit what controls are allowable
INSIDE of the TemplateProperty. An example would be only allowing
'asp:Label' to be used, or as in my case, another usercontrol which
I've created.

So idealy, once one types:
-----------------------------------------------------------------
<Template Property>
<[ctrl-space]
-----------------------------------------------------------------

intelisense only allows you to populate the Template Property with
controls that are allowable, i.e. asp:Label, or a another specified
user control, or something of that nature.

ASP.NET actually already does this with some webcontrols. for an
example, look at:
-----------------------------------------------------------------
<asp:DataGrid runat=server>
<Columns>
</Columns>
</asp:DataGrid>
-----------------------------------------------------------------

inside of the Templated Property, Columns, one can only choose from:
<asp:BoundColumn />
<asp:ButtonColumn />
<asp:EditCommandColumn />
<asp:HyperLinkColumn />
<asp:TemplateColumn />

Any other control inserted in <Columns> will cause compile errors:
Error 4 Validation (ASP.Net): Text is not allowed between the opening
and closing tags for element Columns'.

I'd like to have this same functionality with my controls. Any help
would be greatly appreciated!

Thanx Much,
John Pequeno
.... just another Computer Engineer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top