在頁(yè)面上生成動(dòng)態(tài)控件,另外在有個(gè)事件。Button bu = new Button(); bu.Click += new EventHandler(bu_Click); void bu_Click(object sender, EventArgs e) { throw new NotImplementedException(); }這種的不是必須把它放在頁(yè)面加載時(shí)嗎?那Click才會(huì)走啊。能不能有其他的解決方案啊,動(dòng)態(tài)生成的啊,謝謝啊
1 回答

犯罪嫌疑人X
TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
protected void Page_Load(object sender, EventArgs e)
{
Button btnTest = new Button();
btnTest.Text = "動(dòng)態(tài)添加控件";
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('動(dòng)態(tài)添加控件成功!');</script>");
}
- 1 回答
- 0 關(guān)注
- 357 瀏覽
添加回答
舉報(bào)
0/150
提交
取消