title: How to add onclick event of dynamically added buttons
body: <p>How to add <strong><code>OnClick</code></strong> event of dynamically added buttons in asp.net. I have added buttons dynamically and now I want to create an clickevent for those buttons.</p>
  
  <pre><code> if (dtTasks.Rows[j]["EmpID"].Equals(dtEmployees.Rows[i]["EmpID"]))
   {
         TableRow r = new TableRow();
         TableCell[] cells =  new TableCell();
         Button btn = new Button();
         btn.ID = "btn" + dtTasks.Rows[j]["TaskID"].ToString();
         btn.Text = "Add Comment";
         btn.OnClientClick = "Click";
         cells.Controls.Add(btn);
   }
  </code></pre>