I'm working on some legacy inline Web Forms code. I have added a checkbox which is set by default. The issue is when the checkbox is unchecked, it still flips to checked when the form is submitted. There are no page event handlers per say.
In the JavaScript, if I set an alert it displays the value as blank which is correct when the checkbox is unchecked. However, the checkbox always reverts to its checked state when the form is submitted.
Markup:
<input type="hidden" id="inYard" name="inYard" runat="server" />
<input type='checkbox' id="excludeYard" name='excludeYard' onclick="CheckYardSelection()"
runat="server" />Include Items in Yard
JavaScript:
function CheckYardSelection()
{
var yardCheckbox = document.getElementById('excludeYard');
if (!yardCheckbox.checked)
document.getElementById('inYard').value = "";
else
document.getElementById('inYard').value = "Y";
}
C#:
<script runat="server">
...
if(!String.IsNullOrEmpty(Request.Form["inYard"]))
{
if (Request.Form["inYard"].ToString() == "Y")
{
excludeYard.Value = Request.Form["inYard"].ToString();
excludeYard.Checked = true;
}
}
...
</script>