Can you please tell me what's wrong with the following code?
Panel div = new Panel();
Button btn1 = new Button { Text = "Delete", CommandArgument = "argument", ID = "remove" };
Button btn2 = new Button { Text = "Insert", CommandArgument = "argument2", ID = "insert" };
btn1.Click += new EventHandler(btn_click);
btn2.Click += new EventHandler(btn_click);
div.Controls.Add(btn1);
div.Controls.Add(btn2);
ph_plan.Controls.Add(div); // where ph_plan is a placeholder in the user control
protected void btn_click(object sender, EventArgs e)
{
Button btn = (Button)sender;
if(btn.ID == "remove")
// do this
else
// do that
}
The code above occurs right after a click on a button in the user form. It is supposed to create 2 new buttons with events assigned. Indeed, it creates the buttons but when I click them nothing happens. I guess the events cannot be registered. What am I doing wrong here?