在页面上生成动态控件,另外在有个事件。Button bu = new Button(); bu.Click += new EventHandler(bu_Click); void bu_Click(object sender, EventArgs e) { throw new NotImplementedException(); }这种的不是必须把它放在页面加载时吗?那Click才会走啊。能不能有其他的解决方案啊,动态生成的啊,谢谢啊
1 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
protected void Page_Load(object sender, EventArgs e)
{
Button btnTest = new Button();
btnTest.Text = "动态添加控件";
this.PanTest.Controls.Add(btnTest);
btnTest.Command += new CommandEventHandler(this.On_Button);
}
protected void On_Button(Object sender, CommandEventArgs e)
{
Response.Write("<script language = 'javascript' type = 'text/javascript'>alert('动态添加控件成功!');</script>");
}
- 1 回答
- 0 关注
- 342 浏览
添加回答
举报
0/150
提交
取消