tags:

views:

193

answers:

2

Hi,

I'm trying to limit the possible types of controls that can be put in to the templated area of a templated control in ASP.NET. Does anyone know how to do that?

/Asger

+1  A: 

I'm not sure it makes sense to do this with a template, per se. A template is a property of type ITemplate. I suppose your designer code could attempt to limit what goes into the template, but that's really against the paradigm.

Perhaps what you want is to override the Control.AddParsedSubObject method, or else implement a ControlBuilder to get serious about it.

John Saunders
I suppose one could want to limit the type of controls in a template to, say, only those made by a particular company... I'm not sure if that would make sense, but then people do interesting things.
Ruslan
People do interesting things, but if they want to limit contents of a template, I suggest they use the template mechanism internally and not let their users be frustrated trying to put arbitrary controls in what isn't really a template property.
John Saunders
A: 

John, Thank you very much for those pointers! That'll get me further. I'm not quite sure, why it doesn't make sense though... for example inside a DataGrids column property only certain child-controls are allowed:

BoundColumn ButtonColumn EditCommandColumn HyperLinkColumn

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

/Asger

asgerhallas
Those are not controls inside template areas, but custom tags that a control builder knows how to process and your control knows how to deal with. Build your own control builder and override AddParsedSubObject (http://msdn.microsoft.com/en-us/library/system.web.ui.controlbuilder.aspx).
Ruslan