I want to attach an event to a button clicked generated at runtime. Till this point I've wrote the code, but can't pass the button's ID to the method. Here is my codeThis code does not through any error, another problem is after the click event the controls get washed away. How to prevent this ?\[code\]protected void Button1_Click(object sender, EventArgs e) { int i = int.Parse(TextBox1.Text); for (int x = 1; x <= i; x++) { Button b = new Button(); b.ID = "btn_" + x.ToString(); b.Text = "btn_" + x.ToString(); b.Click += new System.EventHandler(myEventHandler); pnlHolder.Controls.Add(b); } } private void myEventHandler(object sender, EventArgs e) { txtMain.Text = sender.ToString(); // I want to know which button was pressed }\[/code\]