后台动态添加的button,如何触发button_click事件?

后台动态添加的button,需要在Page_Load或者Page_Init重新动态生成才能执行button_click

public Panel GetContrlType()
{
Panel panel = new Panel();
Button btnsearch = new Button();

btnsearch.Text = "查询";
btnsearch.ID = "btnsearch";
btnsearch.Click += new EventHandler(btnseach_Click);
panel.Controls.Add(btnsearch);
}
return panel;
}

protected void Page_Load(object sender, EventArgs e)
{
try
{
Button bsearch = PanelWarp.FindControl("btnsearch") as Button;
(Panel.FindControl("panel") as Panel).Controls.Add(bsearch);
bsearch.Click += new EventHandler(bsearch_Click);
}
catch (Exception ex)
{
throw ex;
}
}

protected void bsearch_Click(object sender,EventArgs e)
{

}

而且在Page_Load若使用if (!IsPostBack),重新加载页面后动态生成的控件会消失

上一篇:关于android 图像格式问题


下一篇:php面向对象的特性:OOP的继承