I am using a html input checkbox control in a modalpopup which runs a javascript function in the onclick
event. Now my challenge is getting the value of the checked property of this control from code-behind to do some behavioral stuff. When I added the runat="server"
property to it and wrote chkIsPrivate.Attributes.Add("onclick", "toggleCheckbox()");
in the page_load, the javascript function would not fire.
I have searched online for a solution but didn't get any. I'm hoping someone will help me out here.
Please note that without the runat="server"
and the line of code in page_load, the javascript function fires when the checkbox control is clicked. But I need to get the value of the checked property in the code-behind.
HTML:
<tr>
<td align="right">Private Campaign:</td>
<td align="left">
<input id="chkIsPrivate" type="checkbox" onclick="toggleCheckbox()" />
</td>
</tr>
<tr id="password_tr" style="display: none">
<td align="right">Password:</td>
<td align="left">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="150px"></asp:TextBox><br />
</td>
</tr>
<tr id="confirmPassword_tr" style="display: none">
<td align="right">Confirm Password:</td>
<td align="left">
<asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password" Width="150px"></asp:TextBox>
</td>
</tr>
JavaScript:
function toggleCheckbox() {
var checkBox = document.getElementById("chkIsPrivate");
var pwd = document.getElementById("password_tr");
var confirmPwd = document.getElementById("confirmPassword_tr");
var hiddenVal = document.getElementById("privateHiddenInput");
if (checkBox.checked) {
pwd.style.display = "table-row";
confirmPwd.style.display = "table-row";
}
else {
pwd.style.display = "none";
confirmPwd.style.display = "none";
}
}