怎么动态生成控件啊

在页面上生成动态控件,另外在有个事件。

Button bu = new Button();
                bu.Click += new EventHandler(bu_Click);
         void bu_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

这种的不是必须把它放在页面加载时吗?那Click才会走啊。能不能有其他的解决方案啊,动态生成的啊,谢谢啊


慕哥6287543
浏览 343回答 1
1回答

犯罪嫌疑人X

protected void Page_Load(object sender, EventArgs e){&nbsp;&nbsp;&nbsp; Button btnTest = new Button();&nbsp;&nbsp;&nbsp; btnTest.Text = "动态添加控件";&nbsp;&nbsp;&nbsp; this.PanTest.Controls.Add(btnTest);&nbsp;&nbsp;&nbsp; btnTest.Command += new CommandEventHandler(this.On_Button);}protected void On_Button(Object sender, CommandEventArgs e){&nbsp;&nbsp;&nbsp; Response.Write("<script language = 'javascript' type = 'text/javascript'>alert('动态添加控件成功!');</script>");}
打开App,查看更多内容
随时随地看视频慕课网APP