Seboko
01-03-2006, 05:31 AM
Hi,
I am developing in ASP.NET using C#. I am in a situation where I have to create a button 'on the fly' when another button is clicked. I have attached the Click eventhandler to the second button button but it is not responding to it.how do I get around this. Here is a rough summary of my code:
public void createButton1(){
Button bt1 = new Button();
bt1.Text = "Button 1";
bt1.Click += new EventHandler(CreateButton2);
bt1.Visible = true;
}
private void CreateButton2(object sender, System.EventArgs e){
Button bt2 = new Button();
bt2.Text = "Button 2";
bt2.Click += new EventHandler(CreateButton3);
bt2.Visible = true;
}
private void CreateButton3(object sender, System.EventArgs e){
Button bt3 = new Button();
bt3.Text = "Button 3";
bt3.Visible = true;
}
Button 1 displays and when clicked on, 'Button 2' is displayed, but clicking on 'Button 2' does not lead to Button 3 to display!! Is it because 'Button 2's click handler (bt2.Click += new EventHandler(CreateButton3)) is defined inside another handler ( CreateButton2 )??? Please help.
I am developing in ASP.NET using C#. I am in a situation where I have to create a button 'on the fly' when another button is clicked. I have attached the Click eventhandler to the second button button but it is not responding to it.how do I get around this. Here is a rough summary of my code:
public void createButton1(){
Button bt1 = new Button();
bt1.Text = "Button 1";
bt1.Click += new EventHandler(CreateButton2);
bt1.Visible = true;
}
private void CreateButton2(object sender, System.EventArgs e){
Button bt2 = new Button();
bt2.Text = "Button 2";
bt2.Click += new EventHandler(CreateButton3);
bt2.Visible = true;
}
private void CreateButton3(object sender, System.EventArgs e){
Button bt3 = new Button();
bt3.Text = "Button 3";
bt3.Visible = true;
}
Button 1 displays and when clicked on, 'Button 2' is displayed, but clicking on 'Button 2' does not lead to Button 3 to display!! Is it because 'Button 2's click handler (bt2.Click += new EventHandler(CreateButton3)) is defined inside another handler ( CreateButton2 )??? Please help.