这段代码是参考MSDN上的例子写的,但是其中CompositeControl在2.0上才支持的,在1.0下必须实现 INamingContainer接口。
源代码
//=====================================================
// Register.cs
using System;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Sockets;
namespace WCLibrary
{
[
AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
DefaultEvent( "Submit "),
DefaultProperty( "ButtonText "),
ToolboxData( " <{0}:Register runat=\ "server\ "> </{0}:Register> "),
]
public class Register : CompositeControl
{
private Button submitButton;
private TextBox nameTextBox;
private Label nameLabel;
private RequiredFieldValidator nameValidator;
private static readonly object EventSubmitKey =
new object();
// The following properties are delegated to
// child controls.
[
Bindable(true),
Category( "Appearance "),
DefaultValue( " "),
Description( "The text to display on the button. ")
]
public string ButtonText
{
get
{
EnsureChildControls();
return submitButton.Text;
}
set