See ThatButton btn=new Button();
btn.Text="Button";
btn.Click += new System.EventHandler(this.btn_Click);
this.Controls[1].Controls.Add(btn);void btn_Click(object sender, System.EventArgs e)
{
Response.Write("hgknight");
}

解决方案 »

  1.   

    完全可以请访问以下地址:
    http://expert.csdn.net/Expert/topic/1118/1118663.xml?temp=.6648218有任何问题请与dillon联系:)
      

  2.   

    我是想这样:
    for(int i=0;i<5;i++)
    {
       Button btn=new Button();
       btn.Text="Button";
       //5个按钮要5个事件,可不可能???
       btn.Click += new System.EventHandler(this.btn_Click);
       Controls.Add(btn);
    }
      

  3.   

    If you want to dynamically create event handlers, you need to emit MSIL code on the fly. I guess you do not want to do that, :-)EventHandler[] ehl = {new EventHandler(this.Click1),new EventHandler(this.Click2)),new EventHandler(this.Click3)),new EventHandler(this.Click4)),new EventHandler(this.Click5) };for(int i=0;i<5;i++)
    {
       Button btn=new Button();
       btn.Text="Button";
       btn.Click += ehl[i];
       Controls.Add(btn);
    }note, to trigger the event handlers, you need to create those buttons before-hand, preferably in Page_Init or Page_Load
      

  4.   


    你是要对每个button都进行不同的处理还是怎么的?
    你的所有处理都可以在
    private void btn_click(..)
    中处理如果你使用楼上的方法。
    如果你只想对一类事件处理,你可以用选择用btn的id号来区分了。
      

  5.   

    谢谢saucer(思归) ,好厉害呀!
    结贴了,来者有分。