日期:2014-05-17 浏览次数:20469 次
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyControls
{
public class MyControl : CompositeControl, INamingContainer
{
protected override void CreateChildControls()
{
if (ChildControlsCreated) return;
Controls.Clear();
Label label = new Label() {Text = "1"};
Button btn = new Button() { Text = "加一" };
btn.Click += (s,e)=>
{
label.Text = (int.Parse(label.Text) + 1).ToString();
};
Controls.Add(btn);
Controls.Add(label);
ChildControlsCreated = true;
}
}
}
<!-- 头部 -->
<%@ Register TagPrefix="myControls" Namespace="MyControls" Assembly="YourAppName" %>