将新事件添加到按钮(add new event to button)
protected void Page_Load(object sender, EventArgs e)
{
Button a = new Button();
a.Width = 100;
a.Height = 100;
a.Text = "one";
a.Click += new EventHandler(test);
form1.Controls.Add(a);
}
protected void test(object sender, EventArgs e)
{
Button b = new Button();
b.Width = 100;
b.Height = 100;
b.Text = "two";
b.Click += new EventHandler(test2);
form1.Controls.Add(b );
Response.Write("aaaaaaaaaaaaaaaaaa");
}
protected void test2(object sender, EventArgs e)
{
Response.Write("bbbbbbbbbbbbbbb");
}
当点击one显示按钮two但是当点击two按钮时不运行test2 ???? 点击two页刷新时。
我想首先点击'one',然后'two'只在点击按钮a后显示按钮
protected void Page_Load(object sender, EventArgs e) { Button a = new Button(); a.Width = 100; a.Height = 100; a.Text = "one"; a.Click += new EventHandler(test); form1.Controls.Add(a); } protected void test(object sender, EventArgs e) { Button b = new Button(); b.Width = 100; b.Height = 100; b.Text = "two"; b.Click += new EventHandler(test2); form1.Controls.Add(b ); Response.Write("aaaaaaaaaaaaaaaaaa"); } protected void test2(object sender, EventArgs e) { Response.Write("bbbbbbbbbbbbbbb"); }when click on one show Button two but when click on twobutton does not run test2???? when click on two page refresh.
i want first click on 'one' and then 'two' show the button only after button a has been clicked
最满意答案
尝试这个:
protected void Page_Init(object sender, EventArgs e) { Button a = new Button(); a.Width = 100; a.Height = 100; a.Text = "one"; a.Click += new EventHandler(test); form1.Controls.Add(a); Button b = new Button(); b.Visible = false; b.Width = 100; b.Height = 100; b.Text = "two"; b.Click += new EventHandler(test2); form1.Controls.Add(b); } protected void test(object sender, EventArgs e) { b.Visible = true; Response.Write("aaaaaaaaaaaaaaaaaa"); } protected void test2(object sender, EventArgs e) { Response.Write("bbbbbbbbbbbbbbb"); }Try this:
protected void Page_Init(object sender, EventArgs e) { Button a = new Button(); a.Width = 100; a.Height = 100; a.Text = "one"; a.Click += new EventHandler(test); form1.Controls.Add(a); Button b = new Button(); b.Visible = false; b.Width = 100; b.Height = 100; b.Text = "two"; b.Click += new EventHandler(test2); form1.Controls.Add(b); } protected void test(object sender, EventArgs e) { b.Visible = true; Response.Write("aaaaaaaaaaaaaaaaaa"); } protected void test2(object sender, EventArgs e) { Response.Write("bbbbbbbbbbbbbbb"); }更多推荐
发布评论