【发布时间】:2014-05-14 08:03:16
【问题描述】:
我想在 asp.net 页面中动态创建按钮并编写代码。通过以下代码动态创建的按钮。
List<string> category = new List<string>();
category.Add("AAA");
category.Add("BBB");
category.Add("CCC");
category.Add("DDD");
category.Add("EEE");
for (int i = 0; i < category.Count; i++)
{
TableRow tr = new TableRow();
TableCell cl = new TableCell();
TableCell cl2 = new TableCell();
Button button = new Button();
button.ID = "raid" + i;
button.Text = category[i];
button.Click +=button_Click;
private void button_Click(object sender, EventArgs e)
{
Response.Write(sender.ToString());
}
现在我想为所有按钮添加点击事件,并想知道哪个按钮点击事件被触发了。 任何的想法? Response.Write(sender.ToString());或 Response.Write(e.ToString());返回公共属性。
【问题讨论】: