The contents of a ASP.net control label are sometimes processed into a node and sometimes treated as a child control. For example, a node is processed as a value of the property text, and a control such as a panel is treated as a child control. First look at how to handle the attributes.
One, processing becomes the attribute
For the contents of a control label, we can control the parsing behavior of the control to its contents through the Class System.Web.UI.ParseChildrenAttribute class.
ParseChildrenAttribute is a class-level attribute identifier that has four constructors:
1.ParseChildrenAttribute (), the childrenAsProperties property is set to False, and is not parsed into a control.
2.ParseChildrenAttribute (Boolean), specifying resolution to control properties.
3.ParseChildrenAttribute (type), the contents of the control's label are parsed into controls of the control type type.
4.ParseChildrenAttribute (boolean,string) Specifies the value of the childrenAsProperties, specifying the default resolved property (Defaultproperty).
By default, control resolves content to child controls, and WebControl because it can identify [ParseChildren (True, "Text")], the default resolves to properties. For simple properties such as a TextBox, you only need to represent the ParseChildren (True, "text"), Defaultproperty ("text")], and for the DropDownList control's Items property, if only the [ParseChildren (True, " Item "), Defaultproperty (" items ")], then how to resolve the items inside? So be sure to tell the attribute's corresponding parsing method.
System.Web.UI.PersistenceModeAttribute is used to control how control properties are saved. The received parameter is the value of the PersistenceMode enumeration, totalling four types:
Attribute: Specifies that the property or event is persisted as a property (attribute);
Encodedinnerdefaultproperty: Specifies that the property is persisted as the only internal text of the ASP.net server control. The property value is HTML-encoded. This designation can only be done on strings;
Innerdefaultproperty: Specifies that the property is persisted as internal text in the ASP.net server control. It also indicates that the property is defined as the default property of the element. Only one attribute can be specified as the default property;
Innerproperty: Specifies that the property is persisted as a nested tag in the ASP.net server control. This is commonly used for complex objects that have their own persistence properties.
So we can see that DropDownList's items attribute is identified as: [PersistenceMode (Persistencemode.innerproperty)], and then on the ListItem Text property, it is identified as [ Persistencemode[persistencemode.encodedinnerdefaultproperty]]. Explanation, because the items property is a complex property, there is a nested label, so we can be sure that the identity type is Innerproperty, and text is the property of the items, Also, the content in the default text is text so it is identified as Encodedinnerdefaultproperty.
Second, processing as a child control
The above describes some of the general methods for handling attributes, and sometimes we need to treat the nodes in tag as child controls, such as control controls. In general we parse the contents of the label into child controls in two ways: 1. Use the Control.addparsesubobjec () method, 2. By building a new ControlBuilder category.
Addparsesubobject () is invoked after the child object has been parsed, notifying the server control that an element (XML or HTML) has been parsed and adds the element to the server control's ControlCollection object.
But if we're going to do some analysis without loading, it just depends on ADDPARSESUBOBJEC (), such as: we need to get rid of some illegal strings before we analyze them. So we can create our own ControlBuilder class to implement. We only need our own ControlBuilder class to inherit from the ControlBuilder class to parse exactly.