把上面代码文件添加到App_Code文件夹中,因为这个文件夹中的代码都将被动态编译。
通过HtmlTextWriter的Write方法,可以将指定内容输出到浏览器上。
下面代码展示了如何在页面中使用上面生成的新控件。
<title>Show Fully Rendered Control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<custom:FullyRenderedControl
ID="FullyRenderedControl1"
Text2="Hello World!"
runat="Server" />
</div>
</form>
</body>
</html>
上面代码注册自定义控件是在页面中进行,也可以在Web配置文件的<Pages>节中为整个网站注册该控件。