Creating an ASP.Net Templated Server control

谁都会走 提交于 2020-01-03 05:34:46

问题


I want to be able to do something like this

<test:TabControl id="" runat="server"....>
    <ItemTemplate>
        <tabItem label="tab1" />
        <tabItem label="tab2" />
    </ItemTemplate>
</test>

The idea being here is that the only acceptable items in "ItemTemplates" are the tabitem types. There are many asp.net controls that use this, for example the ScriptManager class only allows you to specify certain types of objects under its various collections. Maybe thats the key to this.. I want to add a collection as opposed to a template.

The idea is that in code I will then iterate over each "tabItem" and create the tab as I want it to look (probably rendering div's etc).

Ive had a look at most of MSDN link on how to create templated controls but it doesnt seem to do exactly what I want it to.

Would be grateful for some assistance.


回答1:


You need either a templated control or a custom control that can parse its content (Read about ParseChildrenAttribute(typeof())). Take a look at this article. Although not exactly your case it can inspire you.



来源:https://stackoverflow.com/questions/2908260/creating-an-asp-net-templated-server-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!