动态添加控件委托的问题(跪求解决问题的方法)
页面添加一个Panel
<form id= "form1 " runat= "server ">
<div>
<asp:Panel ID= "Panel1 " runat= "server " Height= "50px " Width= "125px ">
</asp:Panel>
</div>
</form>
然后后台实现动态添加LinkButton,并调用MyClick()
protected void Page_Load(object sender, EventArgs e)
{
LinkButton[] lb = new LinkButton[4];
for (int i = 0; i < 4; i++)
{
lb[i] = new LinkButton();
lb[i].ID = "lb "+ i.ToString();
lb[i].Text = "这是动态添加的LinkButton " + i.ToString();
lb[i].Click += new EventHandler(MyClick);//委托
Panel1.Controls.Add(lb[i]);
}
}
//这里再在页面添加一个Panel,在Panel上再动态添加LinkButton,调用MyClick2()
private void MyClick(object sender, EventArgs e)
{
&