How
to access server Checkbox control using javascript in asp.net
Step 1 : First create your website
in asp.net and create one .aspx page .
Step2: Open .aspx page and drag and
drop check box control and onChange event to check box control.
<asp:CheckBox
ID="cbValue" runat="server" Text="Select Value"
onChange="cbValue_onChange(this);" />
Step 3 : Add javascript function to
handle onchange event of check box control.
<script
type="text/javascript">
function cbValue_onChange() {
var check_box = document.getElementById("<%= cbValue.ClientID %>");
if (check_box.checked == true) {
alert("Check box is checked");
}
else {
alert("Check box is UN-checked");
}
}
</script>
function cbValue_onChange() {
var check_box = document.getElementById("<%= cbValue.ClientID %>");
if (check_box.checked == true) {
alert("Check box is checked");
}
else {
alert("Check box is UN-checked");
}
}
</script>
Step 5 : Just run your code and
check is your code is running perfectly and access all event of checkbox
control.
<%@ Page Language="C#"
AutoEventWireup="true" CodeFile="CheckBoxControl.aspx.cs"
Inherits="CheckBoxControl" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function cbValue_onChange() {
var check_box = document.getElementById("<%= cbValue.ClientID %>");
if (check_box.checked == true) {
alert("Check box is checked");
}
else {
alert("Check box is un-checked");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="cbValue" runat="server" Text="Select Value" onChange="cbValue_onChange(this);" />
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function cbValue_onChange() {
var check_box = document.getElementById("<%= cbValue.ClientID %>");
if (check_box.checked == true) {
alert("Check box is checked");
}
else {
alert("Check box is un-checked");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="cbValue" runat="server" Text="Select Value" onChange="cbValue_onChange(this);" />
</div>
</form>
</body>
</html>
No comments:
Post a Comment
Thank you for your interest .