gpt4 book ai didi

c# - 向按钮添加新事件

转载 作者:太空宇宙 更新时间:2023-11-03 20:32:32 24 4
gpt4 key购买 nike

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 时显示 Button two 但当点击 two 按钮时不运行 test2? ??当点击两个页面时刷新。

我想先点击“一”,然后点击“二”仅在单击按钮 a 后显示按钮

最佳答案

试试这个:

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");
}

关于c# - 向按钮添加新事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6744590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com