Setting onchange event for CheckBoxList using the following code doesn't work.
chkListUserGroup.Attributes.Add("onchange", "document.forms[0].isRecordModified.value='true';");
How to set onchange event for CheckBoxList?
Setting onchange event for CheckBoxList using the following code doesn't work.
chkListUserGroup.Attributes.Add("onchange", "document.forms[0].isRecordModified.value='true';");
How to set onchange event for CheckBoxList?
Use onclick event,
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CheckBoxList1.Items.Add("A");
CheckBoxList1.Items.Add("B");
CheckBoxList1.Items.Add("C");
CheckBoxList1.Items.Add("D");
foreach (ListItem item in CheckBoxList1.Items)
{
CheckBoxList1.Attributes.Add("onclick", "document.forms[0].isRecordModified.value=document.activeElement.checked");
}
}
}
Well actually it should be working. Because I write something in my code and it worked. It seems you need to check your javascript code by simply changing it with alert('hello');
foreach (ListItem item in CheckBoxList1.Items)
{
item.Attributes.Add("onchange", "alert('hello')");
}
This is my simple code and it is working.