代码如下:
private void button1_Onclick(ojbect sender, System.EventArgs e)
{
linkbutton templinkbutton = new linkbutton();
templinkbutton.Click += new System.EventHandler(this.templinkbutton_Click)
panel1.Controls.Add(templinkbutton);
} void templinkbutton_Click(object sender, System.EventArgs e)
{
label1.Text = "事件触发了";
}其中button1、panel1、label1是静态的,只有templinkbutton是动态生成的,为什么当我点击templinkbutton时却执行不到templinkbutton_Click事件?请各位大哥帮忙。
private void button1_Onclick(ojbect sender, System.EventArgs e)
{
linkbutton templinkbutton = new linkbutton();
templinkbutton.Click += new System.EventHandler(this.templinkbutton_Click)
panel1.Controls.Add(templinkbutton);
} void templinkbutton_Click(object sender, System.EventArgs e)
{
label1.Text = "事件触发了";
}其中button1、panel1、label1是静态的,只有templinkbutton是动态生成的,为什么当我点击templinkbutton时却执行不到templinkbutton_Click事件?请各位大哥帮忙。
解决方案 »
- AjaxPro 二级联动的Bug
- Asp.net中如何触发TextChanged事件
- 紧急求助 关于iframe嵌套
- 【求教】如何解除ASP.NET上传文件的大小限制?
- 生成临时文件的问题!!!
- comm.Parameters.Add()的参数问题
- 如何设置treeview的每个节点字体?比如上及节点要比下及节点大一些,还有他们的连接线能不能更改颜色或设置?
- 浏览ASP.NET文件配置错误的问题(任务紧,请各位大哥一定要帮帮小弟啊)无法识别的配置节“connectionStrings”
- <-------------------Gridview疑难杂证!!!------------------->
- 问几个有关VSS的问题,不够分可以再加
- VS2005成员资格关于用户管理的问题,在线等。。。
- 一个数据库操作问题
{
linkbutton templinkbutton = new linkbutton();
panel1.Controls.Add(templinkbutton);
templinkbutton.ID = "lb1";
templinkbutton.Click += new System.EventHandler(this.templinkbutton_Click)
} void templinkbutton_Click(object sender, System.EventArgs e)
{
label1.Text = "事件触发了";
}
bool ButtonAdded
{
get
{
object o = ViewState["ButtonAdded"];
if (o == null)
return false;
return (bool)o;
}
set
{
ViewState["ButtonAdded"]= value;
}
}
void AddControl()
{
linkbutton templinkbutton = new linkbutton();
templinkbutton.Click += new System.EventHandler(this.templinkbutton_Click)
panel1.Controls.Add(templinkbutton);
} private void Page_Load(ojbect sender, System.EventArgs e) //make sure it hooks up Page's Load event
{
if (ButtonAdded)
{
AddControl();
}
} private void button1_Onclick(ojbect sender, System.EventArgs e)
{
if (!ButtonAdded)
{
AddControl();
ButtonAdded = true;
}
} void templinkbutton_Click(object sender, System.EventArgs e)
{
label1.Text = "事件触发了";
}