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.