for(int i=1;i<10;i++)
{
Button btn = new Button();
btn.ID = "btn"+i.ToString();
btn.Text="大家好"+i.ToString();
btn.CommandName ="test"+i.ToString();
btn.Click+=new EventHandler(btn_Click);
Page.Controls[1].Controls.Add(btn);
}
private void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
string id = btn.ID;
string commandname = btn.CommandName;
//通过id或者commandname知道当前点击的是哪个按钮,从而决定做什么事
}