The display of ASP.net control will naturally be inseparable from output HTML, CSS, JavaScript and other foreground display content, so the first thing to develop a control is to know how to output the content of the client to display.
First, select the base class
All of the standard controls in ASP.net can be taken as a base class, and if the controls we are developing are simply functional enhancements to the existing standard controls (e.g., you add some random functionality to the checkbox of the TreeView), you can use the standard controls directly as the base class.
In general, if the developed control is not found to be suitable from the standard, it can be inherited from three classes:
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.CompositeControl
The following is a description of the relationships and differences between these three classes:
Control: Provides simple rendering with no support for CSS. such as: Literal control
WebControl: Support for the appearance of the control is established. Suitable for visual control to inherit, such as: Button
CompositeControl: is derived from multiple control comps. Suitable for developing standard controls in the application asp.net.
The relationship between the three: control is the base class for all controls, WebControl is inherited from ASP.net, and CompositeControl is inherited from WebControl.
Second, how to present
The rendering of control
Rendering in the control class is accomplished by means of render. Render's prototype:
protected internal virtual void Render (HtmlTextWriter writer) {...}
The HtmlTextWriter writer parameter is provided at run time by a framework that invokes the Render method, so we can override the Render method to implement the content rendering.
HelloWorld Example:
public class helloworld:control{
protected override void Render (HtmlTextWriter writer)
{
Writer. WriteLine ("Henllo World");
}
}