If a server control was declared like thi开发者_StackOverflow中文版s
<my:customControl id="cc1" runat="server">
Help me obi-wan kenobi!
</my:customControl>
is it possible to access the text between the tags?
If asp.net know how to parse your control (reflect Literal, LiteralControl, TextBox controls to see how its done)
[ControlBuilder(typeof(YourControlBuilder)), DefaultProperty("Text")]
public class YourControl : Control, ITextControl {
}
[Bindable(true), DefaultValue(""), Localizable(true)]
public string Text {
get;
set;
}
public class YourControlBuilder : ControlBuilder {
}
Adding [ParseChildren(true, "Text")] to your custom control class will do this.
You can find more information along with samples here http://msdn.microsoft.com/en-us/library/system.web.ui.parsechildrenattribute.aspx
EDIT
Relevant snippet from the above link
[ParseChildren(true, "Employees")]
Use the ParseChildren attribute to set the ChildrenAsProperties and DefaultProperty properties. Using this constructor, the control parses all child controls as properties and must define a public property named Employees, which it declares as an ArrayList. Nested (child) elements must correspond to child elements of the Employees property or to other properties of the control.
加载中,请稍侯......
精彩评论