asp.net control Development (i) Display control contents

Source: Internet
Author: User

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");

}

}

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.