Asp.net control development (III): process the content between tags

Source: Internet
Author: User
Tags control label

The content between asp.net control labels is sometimes processed as a node and sometimes as a child control. For example:The nodes are processed as the value of the property Text, and controls such as Panel are processed as child controls. First, let's take a look at how to process attributes.

1. process as attribute

You can use the System. Web. UI. ParseChildrenAttribute class to control the parsing behavior of controls between control labels.

ParseChildrenAttribute is a Class-Level Attribute identifier, which has four constructors:

1. ParseChildrenAttribute (): If the ChildrenAsProperties attribute is set to false, it cannot be parsed into a control.
2. ParseChildrenAttribute (Boolean), which is resolved to the control property.
3. ParseChildrenAttribute (Type). The content in the control label is parsed into a control of the control Type.
4. ParseChildrenAttribute (Boolean, String) specifies the value of ChildrenAsProperties and the default parsed property (DefaultProperty ).

By default, Control parses the content into a child Control, while WebControl can identify [ParseChildren (true, "Text")], so it is parsed as an attribute by default. for simple properties such as TextBox, you only need to represent it as [ParseChildren (true, "Text"), DefaultProperty ("Text")]. For the Items attribute of the DropDownList control, if [ParseChildren (true, "Item"), DefaultProperty ("Items")] is identified, how does one parse Items internally? Therefore, you are sure to tell the resolution method corresponding to the property.

System. Web. UI. PersistenceModeAttribute is used to control the storage mode of control attributes. The received parameters are the PersistenceMode enumerated values. There are four types:

◆ Attribute: Specify Attribute or event persistence as Attribute );
◆ EncodedInnerDefaultProperty: Specifies the attribute to be kept as the unique internal text of the ASP. NET Server. The property value is HTML encoded. This can only be specified for strings;
◆ Innerdefaproperty property: Specifies the attribute to be kept as internal text in the ASP. NET Server Control. It also defines this attribute as the default attribute of the element. Only one attribute can be specified as the default attribute;
◆ InnerProperty: Specifies the attribute to be nested in the ASP. NET Server Control. This is usually used for complex objects that have their own persistence attributes.

Therefore, we can see that the identifier of the DropDownList Items attribute is [PersistenceMode (PersistenceMode. InnerProperty)], and then it is identified as [PersistenceMode [PersistenceMode. encodedinnerdefaproperty property] on the Text attribute of ListItem Because the Items attribute is a complex attribute and there is an embedded tag, we can be sure that the identifier type is InnerProperty, and Text is an Items attribute, the content in the default Text is Text, so it is identified as encodedinnerdefaproperty property.

2. processing as a child Control

The above describes some general methods for processing as attributes, and sometimes we need to process the nodes in the Tag as subcontrols, such as Control controls. Generally, we can resolve the content in the tag into a sub-Control using two methods: 1. Use the Control. AddParseSubObjec () method, 2. Build a new ControlBuilder category.

AddParseSubObject () is called only after the sub-object has been analyzed. It notifies the server control that an element (XML or HTML) has undergone syntax analysis and adds the element to the ControlCollection object of the server control.

However, if we want to perform some analysis without loading, it will not work if we only rely on AddParseSubObjec,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.