如果我动态创建ImageButton并将其添加到表格单元格中
TableRow tr = new TableRow();
TableCell tc = new TableCell();
ImageButton imagebutton= new ImageButton();
imagebutton.imageurl=imageurl;
imagebutton.click+= new System.Web.UI.ImageClickEventHandler(click);
tc.Controls.Add(imagebutton);
tr.Controls.Add(tc);
Table1.Rows.Add(tr);单击事件不起作用。
但是,如果我使用Panel而不是table,那么imagebutton就可以工作。更重要的是,如果我将图像按钮直接添加到page中,它也可以正常工作。但我需要在table cell中存储imagebutton。
什么是问题?如何在asp table中创建有效的imagebutton
单击方法为:
protected void click(object sender, EventArgs e)
{
Response.Write("<script type='text/javascript'>alert('OK!');</script>");
}发布于 2012-10-08 19:43:21
什么是问题?
这似乎是一个典型的asp.net页面生命周期问题。原因可能是,应该处理单击的时间、按钮以及表不存在,因为您是在页面生命周期的后期(比如在pre_render中)创建的,或者只在没有回发时创建,或者是在另一个控件事件处理程序中创建的。
如何制作asp表格内的工作图像按钮?
表和按钮的创建以及单击处理程序绑定应该位于
page_load (在为动态控件使用view_state时,在Init中更好)
无论是否在回发时,代码都应该运行。
希望这能有所帮助
https://stackoverflow.com/questions/12778960
复制相似问题