如果服務器控件被宣佈這樣訪問文本
<my:customControl id="cc1" runat="server">
Help me obi-wan kenobi!
</my:customControl>
是有可能訪問標記之間的文本?
如果服務器控件被宣佈這樣訪問文本
<my:customControl id="cc1" runat="server">
Help me obi-wan kenobi!
</my:customControl>
是有可能訪問標記之間的文本?
如果asp.net知道如何分析你的控制(反映文字,LiteralControl,TextBox控件,看看如何做)
[ControlBuilder(typeof(YourControlBuilder)), DefaultProperty("Text")]
public class YourControl : Control, ITextControl {
}
[Bindable(true), DefaultValue(""), Localizable(true)]
public string Text {
get;
set;
}
public class YourControlBuilder : ControlBuilder {
}
添加[ParseChildren(true, "Text")]
您的自定義控制類將做到這一點。
你可以找到這裏的樣品http://msdn.microsoft.com/en-us/library/system.web.ui.parsechildrenattribute.aspx
編輯
從上面的鏈接
[ParseChildren(true, "Employees")]
使用ParseChildren屬性設置 的ChildrenAsProperties相關片段,並沿的更多信息 DefaultProperty屬性。使用此構造函數,控件會將所有 子控件解析爲屬性,並且必須 定義名爲 Employees的公共屬性,它聲明爲 ArrayList。嵌套(子)元素 必須對應於Employees屬性的子元素 或控件的其他 屬性。