ASP.NET复合控件开发

  
    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ServerControl1
{
[DefaultProperty(
" Text " )]
[ToolboxData(
" <{0}:ServerControl1 runat=server></{0}:ServerControl1> " )]
public class ServerControl1 : CompositeControl,INamingContainer
{
[Bindable(
true )]
[Category(
" Appearance " )]
[DefaultValue(
"" )]
[Localizable(
true )]
public string Text
{
get
{
String s
= (String)ViewState[ " Text " ];
return ((s == null ) ? " [ " + this .ID + " ] " : s);
}

set
{
ViewState[
" Text " ] = value;
}
}

public string Tip
{
get { return ViewState[ " aa " ].ToString(); }
set {ViewState[ " aa " ] = value;}
}
TextBox tb1;
Button btn;
Label lb;
protected override void CreateChildControls()
{
Controls.Add(
new LiteralControl( " <h3>第一个数 " ));
tb1
= new TextBox();
tb1.Text
= " 0 " ;
Controls.Add(tb1);
btn
= new Button();
btn.Text
= " 登录 " ;
btn.CommandName
= " login " ;
// btn.Click += new EventHandler(btn_Click);
Controls.Add(btn);
lb
= new Label();
lb.Text
= " aaaaaaaaa " ;
Controls.Add(lb);
}
//点击复合控件中的子控件的事件时触发,事件冒泡出来

protected override bool OnBubbleEvent( object source, EventArgs e)

{
bool handed = false ;
if (e is CommandEventArgs )
{
CommandEventArgs ce
= (CommandEventArgs)e;
if (ce.CommandName == " login " )
{
lb.Text
= " aaaaaaaa " ;
handed
= true ;
}
}
return handed;
}

public class CheckEventArgs : EventArgs
{
private bool match = false ;

public CheckEventArgs( int difference)
{
if (difference == 0 )
{
match
= true ;
}
}
public bool Match
{
get
{
return match;
}
}
}
public event CheckEventHandler Check;
public delegate void CheckEventHandler( object sender, CheckEventArgs ce);
}
}

你可能感兴趣的:(asp.net)