[英]How to read content between tags of asp.net server control
我正在編寫一個asp.net服務器端控件,它有一些簡短的參數傳遞給它,但也需要允許提供大量的自定義HTML代碼。
最簡單的方法我想是允許在服務器控件的標簽之間指定,如下所示:
<MyControl:Example Runat="server" Id="myControl" Message="This is a message">
<p>This is a long piece of HTML a few dozen lines long...</p>
</MyControl>
如何從自定義服務器控件內部訪問標簽之間的文本?
您需要創建模板化控件:
<MyControl:Example Runat="server" Id="myControl" Message="This is a message">
<HtmlContent><p>This is a long piece of HTML a few dozen lines long...</p></HtmlContent>
</MyControl>
HtmlContent
是你的模板。 通常,當我需要模板時,我只需使用PlaceHolder。
public class MyControl : CompositeControl
{
[TemplateContainer(typeof(PlaceHolder))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public PlaceHolder HtmlContent { get; set; }
... render stuff
}
以下是MSDN上的一個示例:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.