服务器控件与组件开发(2).简单得要死的控件
2007-07-31 14:01
302 查看
服务器控件与组建开发(2).简单得要死的控件
2-1:自定义控件
说明:继承自System.Web.UI.Control,主要是重载Render方法。把控件的html语句写出来。
文件名:SelfControl.cs
代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace SelfControls
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// SelfControl HelloWorld
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public class SelfControl : Control
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private string _Name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 自定义的一个属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string Name
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _Name = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _Name; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 一句一句把html代码写出来.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 当然写的方式有多种.下机是最简单的一种.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 也可以用HtmlTextWriterAttribute;HtmlTextWriterStyle;HtmlTextWriterTag;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 定义的一些枚举值.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// <param name="writer"></param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected override void Render(HtmlTextWriter writer)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<table border=1>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<tr>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("this is a self control of " + _Name);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("HelloWorld!");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</tr>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</table>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
这些代码产生的画面如下:比较难看,赫赫。
![](http://p.blog.csdn.net/images/p_blog_csdn_net/qim/320755/o_selfcontrol.gif)
2-2:自定义用户控件
说明:用户控件继承的类不同于以上所说的自定义控件,它继承自System.Web.UI.UserControl,而
UserControl:TemplateControl:Control,说明用户控件有了进一步的封装。
文件名:WebUserControl.ascx,WebUserControl.ascx.cs
前台代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"
Inherits="WebUserControl" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table border="1">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><asp:Button ID="Button1" runat="server" Text="Button" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
后台代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Collections;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 什么也没写
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class WebUserControl : System.Web.UI.UserControl
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
效果:
![](http://p.blog.csdn.net/images/p_blog_csdn_net/qim/320755/o_usercontrol.gif)
2-3:做一个页面来调用上面两个控件。
说明:相当于一个容器,把上面两个控件装载进来。
文件名:Default.aspx
代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Register Namespace ="SelfControls" TagPrefix="cc1" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Register Src="~/WebUserControl.ascx" TagName = "WebUser" TagPrefix = "cc2" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml" >
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>HelloWorld</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<cc1:SelfControl ID="SelfControl1" runat="server" Name="">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</cc1:SelfControl>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<br />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<cc2:WebUser ID = "WebUser1" runat ="server" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
2-4:over。算是一个helloworld。继续学习。
2-1:自定义控件
说明:继承自System.Web.UI.Control,主要是重载Render方法。把控件的html语句写出来。
文件名:SelfControl.cs
代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace SelfControls
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// SelfControl HelloWorld
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public class SelfControl : Control
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private string _Name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 自定义的一个属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string Name
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _Name = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _Name; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 一句一句把html代码写出来.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 当然写的方式有多种.下机是最简单的一种.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 也可以用HtmlTextWriterAttribute;HtmlTextWriterStyle;HtmlTextWriterTag;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 定义的一些枚举值.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// <param name="writer"></param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected override void Render(HtmlTextWriter writer)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<table border=1>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<tr>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("this is a self control of " + _Name);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("<td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("HelloWorld!");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</td>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</tr>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
writer.Write("</table>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
这些代码产生的画面如下:比较难看,赫赫。
![](http://p.blog.csdn.net/images/p_blog_csdn_net/qim/320755/o_selfcontrol.gif)
2-2:自定义用户控件
说明:用户控件继承的类不同于以上所说的自定义控件,它继承自System.Web.UI.UserControl,而
UserControl:TemplateControl:Control,说明用户控件有了进一步的封装。
文件名:WebUserControl.ascx,WebUserControl.ascx.cs
前台代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"
Inherits="WebUserControl" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table border="1">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><asp:Button ID="Button1" runat="server" Text="Button" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
后台代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Collections;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// 什么也没写
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class WebUserControl : System.Web.UI.UserControl
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
效果:
![](http://p.blog.csdn.net/images/p_blog_csdn_net/qim/320755/o_usercontrol.gif)
2-3:做一个页面来调用上面两个控件。
说明:相当于一个容器,把上面两个控件装载进来。
文件名:Default.aspx
代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Register Namespace ="SelfControls" TagPrefix="cc1" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Register Src="~/WebUserControl.ascx" TagName = "WebUser" TagPrefix = "cc2" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml" >
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>HelloWorld</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<cc1:SelfControl ID="SelfControl1" runat="server" Name="">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</cc1:SelfControl>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<br />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<cc2:WebUser ID = "WebUser1" runat ="server" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
2-4:over。算是一个helloworld。继续学习。
相关文章推荐
- ASP.NET 2.0服务器控件与组件开发高级编程:为自定义控件添加设计时属性
- 读书片断之《ASP.NET 2.0 服务器控件与组件开发高级编程》
- ASP.NET 2.0服务器控件与组件开发高级编程
- ASP.NET 2.0服务器控件开发之简单属性
- 庖丁解牛ASP.NET3.5控件和组件开发技术-(1)服务器控件概述
- 服务器控件与组件开发(1).开发总括
- ★★★【庖丁解牛:纵向切入Asp.net 3.5控件和组件开发技术系列—(3)从零开始开发服务器控件】★★★
- ASP.NET 2.0服务器控件开发之简单属性
- ASP.NET 2.0服务器控件与组件开发中文版即将出版
- 庖丁解牛ASP.NET3.5控件和组件开发技术-(1)服务器控件概述
- (一)庖丁解牛Asp.net3.5控件和组件开发技术系列—服务器控件开发中的调试技术-郑健
- ★★★【庖丁解牛:纵向切入Asp.net 3.5控件和组件开发技术系列—(2)服务器控件开发中的调试技术】★★★
- ASP.NET 2.0服务器控件与组件开发高级编程
- 开发简单的自定义服务器控件
- 开发简单的 ASP.NET 服务器控件(2)
- 开发简单的 ASP.NET 服务器控件
- ASP.NET 2.0服务器控件开发之简单属性
- 庖丁解牛ASP.NET3.5控件和组件开发技术-(3)从零开始开发服务器控件
- 【摘录】ASP.NET 2.0服务器控件与组件开发高级编程(第2章摘录1)
- ASP.NET 2.0服务器控件开发之简单属性