简体   繁体   中英

ASP.NET Custom Control - Default Template?

I know this is really picky, but can I have one template inside a user control:

<uc:MyUserControl runat="server" ID="test">
    <div><b>Test</b></div>
    <asp:PlaceHolder runat="server" id="pH" />
</uc:MyUserControl>

Instead of what I have now which requires me to:

<uc:MyUserControl runat="server" ID="test">
    <Content>
        <div><b>Test</b></div>
        <asp:PlaceHolder runat="server" id="pH" />
    </Content>
</uc:MyUserControl>

Basically I want my control to have only one ITemplate inside of it.

Content is an ITemplate property of the user control? Try using this:

[PersistenceMode(PersistenceMode.InnerDefaultProperty)]

http://msdn.microsoft.com/en-us/library/system.web.ui.persistencemode.aspx

EDIT: Plus, you need to add the [ParseChildren(True, "DEFAULTPROPERTY")] attribute to the control as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM