【发布时间】:2011-05-30 01:39:40
【问题描述】:
我有一个服务器控件,它有一个作为 InnerProperty 的 PlaceHolder。在渲染时的类中,我需要获取应该在 PlaceHolder 中的文本/HTML 内容。这是前端代码的示例:
<tagPrefix:TagName runat="server">
<PlaceHolderName>
Here is some sample text!
</PlaceHolderName>
</tagPrefix:TagName>
这一切都很好,除了我不知道如何检索内容。我没有看到 PlaceHolder 类公开的任何渲染方法。这是服务器控件的代码。
public class TagName : CompositeControl
{
[TemplateContainer(typeof(PlaceHolder))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public PlaceHolder PlaceHolderName { get; set; }
protected override void RenderContents(HtmlTextWriter writer)
{
// i want to retrieve the contents of the place holder here to
// send the output of the custom control.
}
}
有什么想法吗?提前致谢。
【问题讨论】:
-
我以前从未见过有人这样做。如果它真的有效,我会感到非常惊讶。是什么让您认为“这一切都有效”?
-
嗨,约翰,我刚刚发布了这个问题的答案。据我所知,尽管任何 Web 控件都应该能够呈现为其原始 HTML 输出,但要回答您的问题。
标签: c# asp.net controls placeholder composite-controls