我已经搜索并尝试了很多东西,但我无法让以下代码工作。似乎当我在 c# 中有三个按钮时,如果我单击第一个按钮,它将正确触发。但是,当我单击第二个按钮时,加载第三个按钮不起作用。回到第一个。由于某种原因,事件似乎没有超过第一级。提前感谢您的帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
public partial class testingSandbox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
boot();
}
public void boot()
{
firstFunc();
}
public void firstFunc()
{
Debug.WriteLine("func1");
Button btn1 = new Button();
btn1.Text = "btn1";
btn1.ID = "btn1";
btn1.Click += new EventHandler(secFunc);
form1.Controls.Add(btn1);
}
public void secFunc(object sender, EventArgs e)
{
Debug.WriteLine("func2");
Button btn2 = new Button();
btn2.Text = "btn2";
btn2.ID = "b2";
btn2.Click += new EventHandler(thirdFunc);
form1.Controls.Add(btn2);
Button btn1 = (Button)this.FindControl("btn1");
//btn1.Click-=new EventHandler(secFunc);
}
public void thirdFunc(object sender, EventArgs e)
{
Debug.WriteLine("func3");
Button btn3 = new Button();
btn3.Text = "btn3";
btn3.ID = "b3";
btn3.Click += new EventHandler(fourthFunc);
form1.Controls.Add(btn3);
}
public void fourthFunc(object sender, EventArgs e)
{
Debug.WriteLine("func4");
Button btn4 = new Button();
btn4.Text = "btn4";
form1.Controls.Add(btn4);
}
}