问题描述
我写了以下动态代码来调用CheckChanged事件。
但我无法调用此事件。
请给,给我帮忙解决实际问题是什么?
CheckBox chk = new CheckBox() ;
string uniqueID = System.Guid.NewGuid()。ToString()。子串(0,5);
chk.ID =chktrait+ cn.AspectID +_+ cn.TraitID + uniqueID;
chk.Text = cn.ValueName;
chk.AutoPostBack = true;
chk.CheckedChanged + = new EventHandler(CheckBox_CheckChanged);
protected void CheckBox_CheckChanged(object sender,EventArgs e)
{
//写入触发事件的控件的客户端ID
响应。写(((CheckBox)发送者).ClientID);
}
I written following dynamic code for call check box CheckChanged event.
But I unable to call this event.
Please, give me help what is the actual issue?
CheckBox chk = new CheckBox();
string uniqueID = System.Guid.NewGuid().ToString().Substring(0, 5);
chk.ID = "chktrait" + cn.AspectID + "_" + cn.TraitID + uniqueID;
chk.Text = cn.ValueName;
chk.AutoPostBack = true;
chk.CheckedChanged += new EventHandler(CheckBox_CheckChanged);
protected void CheckBox_CheckChanged(object sender, EventArgs e)
{
//write the client id of the control that triggered the event
Response.Write(((CheckBox)sender).ClientID);
}
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
CheckBox chk = new CheckBox();
string uniqueID = System.Guid.NewGuid().ToString().Substring(0, 5);
chk.ID = "chkTest";
chk.Text = "Test";
chk.AutoPostBack = true;
chk.CheckedChanged += new EventHandler(CheckBox_CheckChanged);
this.form1.Controls.Add(chk);
}
protected void CheckBox_CheckChanged(object sender, EventArgs e)
{
//write the client id of the control that triggered the event
lblTest.Text = ((CheckBox)sender).ClientID;
}
希望这会有所帮助。
Hope this will be of help.
这篇关于动态复选框CheckedChanged不是火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!