There were a couple of problems with the system I'm working on. It's 20 years old and was initially developed under .NET 2.0 (I believe), it's now running under .NET 4.8. The code itself wasn't off by much, thanks to @barmar, I got the proper checkbox in the click function. The code now reads:
$(document).ready(function() {
$('#<%= CheckBoxList_Items.ClientID %> :checked').click(function() {
if ($(this).is(":checked")) {
alert("ID # " + $(this).val() + " was just checked.");
} else {
alert("ID # " + $(this).val() + " was just unchecked.");
}
});
});
Note the :checked
portion of the function declaration.
The $(this).val()
portion of the code was returning on
because the data portion of the checkboxlist control wasn't being rendered because in the web.config
file there was this setting: <pages controlRenderingCompatibilityVersion="3.5">
. I removed the controlRenderingCompatibilityVersion="3.5
portion of the tag and the checkboxlist data is now being rendered and $(this).val()
returns the data value of the checkbox in the list that is clicked.