About asp.net the HTML code of a child control for a custom control to persist

Source: Internet
Author: User
Tags define html page variable
Asp.net| control ASP. NET custom controls are a good model for building software in a Web page like a stack of wood, and you can

Use a large number of Third-party controls to accomplish features you are not good at. However, it is difficult to write custom controls.

All along, how to keep child control generation code in ASPX design-time pages The problem is disturbing me. Near-paragraph research has

Microsoft's IE WebControl in the TreeView control, and finally find out the problem, not alone, special will it

summed up, and did a sample project, put on my website (http://www.aspxcontrol.com/blog) for netizens

Download.
To sum up, the main points are as follows:
1. Define the child control as a class, such as public class noteitem{}, so that the child control is not

When dragged into the toolbox, this attribute can be used: [ToolboxItem (false)]
2. The child control should be a collection class, referenced system.collection, defined:
public class NoteItemCollection:System.Collections.CollectionBase
3. Implementing members:
ADD (), This[int].
4. Define the Add attribute in the main class:
[DesignerSerializationVisibility (Designerserializationvisibility.content)]
[PersistenceMode (Persistencemode.innerdefaultproperty)]
[Editor (typeof (CollectionEditor), typeof (UITypeEditor))]
If you implement your own editor, you can replace typeof (CollectionEditor) with your own, which can be WinForm

, can refer to the TreeView source.
5. Define a set variable and a ArrayList variable in the main class, such as:
Private Noteitemcollection _notes;
Private ArrayList Al;
Write inside the constructor:
{
Al = new ArrayList ();
_notes = new Noteitemcollection (AL);
}
This way, when you add a child control, you add a similar:<waki:sample> to the ASPX HTML page
<waki:Note>
<waki:item id= "1" ></waki:item>
<waki:item id= "2" ></waki:item>
</waki:Note>
</waki:sample> Such code, you can avoid allowing users to enter the XML code themselves.





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.