我想在页面中动态添加一个用户控件。单击按钮时必须添加用户控件:
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事件中必须注册事件。
那么解决问题的最佳方法是什么? 谢谢
最佳答案
我认为这篇文章应该可以帮助您解决问题,它准确地讨论了您要实现的目标:
关于c# - 初始化后动态注册按钮点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18464117/