C# 添加动态复选框句柄CheckedChanged事件ASP.NET
我想知道为什么事件没有触发&如何找到哪个复选框控件触发了事件C# 添加动态复选框句柄CheckedChanged事件ASP.NET,c#,asp.net,C#,Asp.net,我想知道为什么事件没有触发&如何找到哪个复选框控件触发了事件 chkList1 = new CheckBox(); chkList1.Text = row["subj_nme"].ToString(); chkList1.ID = row["subjid"].ToString(); chkList1.Checked = true;
chkList1 = new CheckBox();
chkList1.Text = row["subj_nme"].ToString();
chkList1.ID = row["subjid"].ToString();
chkList1.Checked = true;
chkList1.Font.Name = "Verdana";
chkList1.Font.Size = 12;
chkList1.AutoPostBack = true;
chkList1.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
Panel1.Controls.Add(chkList1);
protected void CheckBox_CheckedChanged(object sender, EventArgs e)
{
Label1.Text = "Called";
}
如果事件没有触发,可能是因为以下两个原因之一:
CausesValidation
设置为falsesender
参数找出触发事件的控件
protected void CheckBox_CheckChanged(object sender, EventArgs e)
{
//write the client id of the control that triggered the event
Response.Write(((CheckBox)sender).ClientID);
}
在哪里动态创建复选框?您是否也最迟在page_load的回发中使用与以前相同的ID重新创建它?
对象发送者是您单击它时触发事件的复选框。只需将其转换为复选框
。我正在加载页面上创建复选框。