R – single template server control

asp.netcustom-server-controls

Is it possible to have a custom server control with a single template (meaning the user can put any text they want) without having to require the an "ItemTemplate" like in a FormView control?

I would want the control in Source View to look like this

<foo:mycontrol runat="server" id="controlid">

User puts whatever html content they want here

</foo:mycontrol>

INSTEAD OF THIS

<foo:mycontrol runat="server" id="controlid">

<ItemTemplate>

User puts whatever html content they want here

</ItemTemplate>

</foo:mycontrol>

My custom server control needs to add 2 asp.net panel controls and the ajax collapsiblepanel control. one panel will be the expand/collapse panel and the other panel is what I would want to put the user text into and then have the collapsible panel collapse and hide the panel.

I know how to do this (at least I think I do) creating a composite server control and using ITemplate but that requires the child <ItemTemplate> tag in source view.

Any ideas?

Best Answer

I haven't tested this but I would think you could do this by inheriting from the literal or label control and then reading/writing to the Text property.

p.s. next time when you post a question check the preview to see if it's readable and format code with 4 spaces in-front so it's actually shown and syntax highlighted.

Related Topic