怎样正确触发预定义事件?
今天发现在竟然不知道怎么触发预定义事件,怎么弄都出错。
跟自定义的事件的触发完全不是同一回事情,郁闷中。。。
预定义事件:
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
...
#region Web 窗体设计器生成的代码
...
this.Button1.Click += new System.EventHandler(this.Button1_Click);
..
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
//
}
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//下面这两行都会报错
//Button1.Click(sender,e);
//Button1.Click(null,null);
}
自定义事件:
private delegate void SugTypeEventHandler(object sender);
private event SugTypeEventHandler TypeCheck;
private void TypeSelected(object sender)
{}
private void SetSugCodeMiddle(object sender)
{}
private void Page_Load(object sender, System.EventArgs e)
{
TypeCheck += new SugTypeEventHandler(TypeSelected);
TypeCheck += new SugTypeEventHandler(SetSugCodeMiddle);
//调用自定义事件
TypeCheck(SugType);
}