Reputation: 303
I'm having few checkboxes which are dynamically created using c# code- behind. At client side using jquery I want to make the checkbox as checked, but the checked value is not reflected on the UI. I have browsed for the solution and it suggest something related to VIEWSTATE. Here is my C# code and Jquery where I'm setting the Checkbox value.
C#. Code
CheckBox checkbox = new CheckBox();
checkbox.ID = "CheckBox" + i++;
checkbox.InputAttributes["class"] = "skin-line-grey icheck-label form-label";
checkbox.ClientIDMode = ClientIDMode.Static;
checkbox.Text = item.Text;
PnlEventList.Controls.Add(checkbox);
Jquery. Checkbox1 is the ID for checkbox been dynamically created. Same I have 7 more checkboxes.
$('#CheckBox1').prop('checked', true);
Upvotes: 0
Views: 481
Reputation: 346
CheckBox property, lying not in properties or attribute collection. Use this:
$('#CheckBox1')[0].checked = true;
Or this:
document.getElementById("CheckBox1").checked = true;
Upvotes: 2
Reputation: 1570
Try this: $('#Checkbox1').prop('checked', true);
This is case sensitive.
Upvotes: -1