Why is the check and unchecked not working in asp.net, it almost like the property checked is not showing?
I’m trying to use jquery to get the check and unchecked boolean in to an alert?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.8.1.js" type="text/javascript"></script>
<script src="JScript1.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" />
</div>
</form>
</body>
</html>
$(document).ready(function () {
$("#CheckBox1").click(function () {
if ($(this).is(':checked')) {
alert("true");
} else {
alert("false");
}
});
});
Use Firebug to check the ID of the element. I know that ASP.NET will append a random ID string to the end of your CheckBox1 and therefore Jquery would not pick it up.
The best approach would be to surround it by standard HTML and call the element from the parent.
and then
});