我想在页面中动态添加用户控件。单击按钮时必须添加用户控件:
protected void BtnAddCpe_Click(object sender, EventArgs e)
{
CPEData cpeControl = Page.LoadControl("/Controls/Cpe/CPEData.ascx") as CPEData;
cpeControl.ID = "Cpes_" + this.PhCPE.Controls.Count;
cpeControl.ValidationGroup = "new_cpe_order";
cpeControl.CPETypeList = this.SetCpeTypeList(this.CPETypeList);
cpeControl.AggiungiCpeType += new CpeTypeEventHandler(Cpes_AggiungiCpeType);
this.PhCPE.Controls.Add(cpeControl);
}
显然这条线不起作用
cpeControl.AggiungiCpeType += new CpeTypeEventHandler(Cpes_AggiungiCpeType);
因为必须在Init事件期间注册事件。
那么解决问题的最佳方法是哪种? 感谢名单