Source: http://blog.csdn.net/caoxicao
Author: caoxi grass
Reprinted please indicate the source
This time, some tips will be written in the development process of the DOTNET custom control, so that you can remember more firmly, and also provide a learning direction for later people.
1.Custom Controls are derived from the webcontrol class instead of the control class.To inherit many additional attributes.
For example, attributes related to height, width, Font, and other styles. These attributes allow page developers to customize the appearance of controls. When derived from the webcontrol class, follow the following conventions:
◎ Contains a reference to the system. Web. UI. webcontrols namespace.
◎ Do not reload the render method to directly write data to the output stream. This is because the render method of webcontrol implements a piece of code that provides tags with style information. To provide content in the control label, you can use the reload rendercontents method.
2.Select a base class for the control
◎ If the control is to generate non-visualized elements or display them to non-HTML clients, it is derived from the system. Web. UI. control class.
Tags <meta> and <XML> are examples of non-visualized element display.
◎ If You Want To provide HTML for generating visual interfaces on the client, you should derive from system. Web. UI. webcontrols. webcontrol.
◎ When you want to extend or modify the functions of a control, you should derive from an existing control, such as labels, buttons, and text boxes. It can be derived from any control or custom control in the namespace system. Web. UI. webcontrols. But do not derive from the control in the system. Web. UI. htmlcontrols naming control.
To understand this part, we 'd better look at the implementation of the render method in webcontorl.
Protected overide void render (htmltextwriter writer ){
Renderbegintag (writer );
Rendercontents (writer );
Renderendtag (writer );
}
It can be seen that the render in webcontrol has been formatted. Renderbegintag indicates the start of the tag, for example, writer. renderbegintag ("<H2>") writer. renderendtag () indicates that the tag is included in <H2> </H2>
Let's take a look at the rendercontents implementation code in webcontrol:
Protected virtual void rendercontents (htmltextwriter writer ){
// You can see that the rendercontents method calls back the render method of the base class.
Base. Render (writer)
}
To sum up, you need to reload the rendercontents method when you want to generate content in the Web Control label.
==============================================
Write it here today.