Effect:
On the page where this control is placed: xml/html
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Test6.aspx.cs" inherits= "Test6"%>
<% @Register tagprefix= "Custom" namespace= "Mycomponents"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<custom:mygrid runat= "Server" id= "Mygrid"/>
</div>
</form>
</body>
And put the code about the control into the App_Code file, make a comment and see for yourself:
Copy Code code as follows:
Using System;
Using System.Web.UI;
Namespace Mycomponents
{
System.Web.UI.Control all controls share this class, and control development must inherit from controls
public class Mygrid:control
{
Overrides the Render method of the control class, because all controls inherit from, so almost all controls have this method
HtmlTextWriter class, the main job is that we write tag characters and text output
protected override void Render (HtmlTextWriter writer)
{
Writer. Write ("<table border=\" 1\ ">");
Writer. Write ("<tr><th> webmaster </th><th> site </th></tr>");
Writer. Write ("<tr><td> Ahanan </td><td>sosuo8.com</td></tr>");
Writer. Write ("</table>");
Base. Render (writer);
You can go directly to the code in the App_Code folder, you can automatically compile, or you can create a Web control library
}
}
}