title: how to create an asp button dynamically and add event to it
body: <p>I'm trying to create a button dynamically on asp.net,but I can't add the event to it.What is wrong or missing below?</p>
  
  <p>Thanks in advance</p>
  
  <p>$      </p>
  
  <pre><code>    Button btn2 = new Button();
      btn2.ID = "btnEdit";
      btn2.Text = "Edit Member";
      btn2.Click += new EventHandler(btnEdit_Click);
      form1.Controls.Add(btn2);
  </code></pre>
  
  <p>I also tried like this:</p>
  
  <p>$</p>
  
  <pre><code>    Button btn2 = new Button();
      btn2.ID = "btnEdit";
      btn2.Text = "Edit Member";
      btn2.Attributes.Add("OnClick","btnEdit_Click);
      form1.Controls.Add(btn2);
  </code></pre>