How to connect onchange event to CheckBoxList? Missing InputAttributes attributes?

Setting the onchange event for CheckBoxList using the following code does not work.

chkListUserGroup.Attributes.Add("onchange", "document.forms[0].isRecordModified.value='true';"); 

How to set onchange event for CheckBoxList?

+4
source share
3 answers

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) { item.Attributes.Add("onclick", "document.forms[0].isRecordModified.value=document.activeElement.checked"); } } } 
+6
source

Use this code to handle click events in the checkbox list in vb.net

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim li As ListItem For Each li In CheckboxList1.Items li.Attributes.Add("onclick", "alert('hello')") Next End If 
+1
source

Well, actually it should work. Because I am writing something in my code and it worked. It seems you need to check your javascript code just by changing it with alert ('hello');

  foreach (ListItem item in CheckBoxList1.Items) { item.Attributes.Add("onchange", "alert('hello')"); } 

This is my simple code and it works.

0
source

All Articles