Checkbox is selected but is returning false in code behind

I have a checkbox in a form. When I click the only button on the form, it calls a JS function. I put some logic in the function that alerts me if the checkbox is selected. If the checkbox is selected, it comes back true. Otherwise it comes back false. The JS alert works perfectly as intended.

However, after the postback from the button being clicked, I have logic pertaining to the Checkbox in C#. I have put the logic everywhere in the page and still cannot figure out the problem.

if (myCheckbox.Checked)
{
  // Certain code is implemented.
}
else
{
  // Other code is implemented.
}

Right now I have the code in the Page_LoadComplete(object sender, EventArgs e). I have verified in the code behind .cs file, any code pertaining to the status of the Checkbox (example: myCheckbox.Checked = false) is commented out. I have been looking at this around the clock for two days and it is driving me crazy. How is it possible I am getting a false value after the postback when the Javascript says it is selected (when it is selected) and not selected (when it is not selected).

  • I tried putting the logic (if (checkBox.checked)) everywhere in the page and am getting the same result.

  • I tried calling a JS function from the C# code behind file but found out I can’t return a value that way.

  • I tried using a HiddenField value to store the status of the Checkbox and that was unsuccessful as well.

  • I’ve searched the internet trying similar things other people used but had no luck.