I have some code which involves dynamically creating new buttons, when a user clicks on a particular button. However the EventHandlers defined for these dynamically created buttons do not execute when I click on any one of them. Here is the errant code snippet:
protected void Page_Load(object sender, EventArgs e)
{
.......
btn1.Click += new EventHandler(this.btn1_Click);
.......
}
protected void btn1_Click(object sender, EventArgs e)
{
.......
LinkButton btn2 = new LinkButton();
btn2.Click += new EventHandler(this.btn2_Click);
.........
}
protected void btn2_Click(object sender, EventArgs e)
{
.......
}
The code execution never enters btn2_Click(). Am I doing something wrong here?