一个自定义控件,里面就包含一个button
b是一个Button的实例。
protected override void Render(HtmlTextWriter output)
{
b.RenderControl(output);
this.EnsureChildControls();
base.Render(output);
}
protected override bool OnBubbleEvent(object source, EventArgs args)
{
if(source is Button)
{
OnLogin(System.EventArgs.Empty);
return true;
}
else
return base.OnBubbleEvent (source, args);
}
protected void OnLogin(EventArgs e)
{
if(Login!=null)
this.Login(this,e);
}然后在在另一个项目中给这个控件添加事件处理 但是没有作用,请大家帮忙看看那里写错了!
b是一个Button的实例。
protected override void Render(HtmlTextWriter output)
{
b.RenderControl(output);
this.EnsureChildControls();
base.Render(output);
}
protected override bool OnBubbleEvent(object source, EventArgs args)
{
if(source is Button)
{
OnLogin(System.EventArgs.Empty);
return true;
}
else
return base.OnBubbleEvent (source, args);
}
protected void OnLogin(EventArgs e)
{
if(Login!=null)
this.Login(this,e);
}然后在在另一个项目中给这个控件添加事件处理 但是没有作用,请大家帮忙看看那里写错了!
event Login 的代码。
http://huobazi.cnblogs.com/archive/2006/04/08/TwoDropDownListInDataGridAndBubbleEvent.html
public event EventHandler SubClick;
public event EventHandler CanClick;
#endregion.........protected override bool OnBubbleEvent(object source, EventArgs args)
{
bool handled =false;
if(args is CommandEventArgs)
{
CommandEventArgs ce=(CommandEventArgs) args;
if(ce.CommandName=="Submit")
{
OnSubClick(ce);
}
else if(ce.CommandName=="Cancle")
{
OnCanClick(ce);
}
handled=true;
}
else
{
OnNameTextChanged(args);
handled=true;
}
return handled;
}
.........public void OnSubClick(EventArgs e)
{
if(SubClick!=null)
SubClick(this,e);
} public void OnCanClick(EventArgs e)
{
if(CanClick!=null)
CanClick(this,e);
}