. Net provides you with a variety of controls, rich enough. But sometimes you want to develop some of your own controls to improve development efficiency or implement some special functions.
The following describes how to create a most basic web composite control.
First, create a C # class library project named MyControl. Delete the default class file class1 and create our own class file MyControl. cs.
Now we add a password to it.
First, modify the generated code to be like this.
We will use the following reference:
Using System;
Using System. IO;
Using System. Drawing;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. ComponentModel;
Ensure that our MyContro is inherited from WebControl.
Public class MyControl: WebControl
Next we will rewrite the following two functions, which are required.
Protected override void Render (HtmlTextWriter writer)
Protected override void CreateChildControls ()
Modify the first function as the following code:
Protected override void Render (HtmlTextWriter writer)
{
This. CreateChildControls ();
Base. Render (writer );
}
Modify the second function as the following code:
Protected override void CreateChildControls ()
{
// Clear the existing child control and its ViewState
This. Controls. Clear ();
This. ClearChildViewState ();
// Generate control tree
// Generate an environment table (one row, two cells)
Table myTable = new Table ();
// Build the table row to generate rows in the table
TableRow row = new TableRow ();
MyTable. Rows. Add (row );
// Generate cells
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