在我的应用程序中,我动态创建了一系列按钮。我正在尝试为这些按钮引发 onclick 事件并更改我单击的按钮的文本。我为此尝试了以下代码,但它不起作用。我该怎么做?.任何建议?
代码:
for (int i = 0; i < 5; i++)
{
lbl = new Button[5];
lbl[i] = new Button();
lbl[i].Text = "hi";
lbl[i].Width = 30;
lbl[i].Click += new EventHandler(lbl_click);
//lbl[i].CssClass = "label";
div1.Controls.Add(lbl[i]);
}
点击事件:
protected void lbl_click(object sender, EventArgs e)
{
Button[] lbl = sender as button[];
lbl[i].Text = "clicked";
}