I’m using an html file like below (tv.html):
<form action="myaspx.aspx?appid=5018" method="post" id="formSubscription" name="formSubscription">
<input type="checkbox" id="chckIsConfirm" name="chckIsConfirm"/> I Confirm
<input type="submit" value="Ok" />
</form>
And trying to get it from “myaspx.aspx”. And the code behind is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var r = HttpContext.Current.Request["chckIsConfirm"];
//Or
NameValueCollection nvc = Request.Form;
//Or
var a = Request.Form.AllKeys;
}
}
But I cannot pass the value of “chckIsConfirm”. All keys comes empty.. What am I doing wrong?
UPDATE: Only when I check the checkbox it comes as “ON” other times just NULL.
Thanks in advance
That’s the default behavior for checkboxes in most browsers. If it’s not checked the browser will not send it with the request. As a workaround add a hidden field that has the same name as the checkbox and value “0”, “OFF”, “FALSE” or whatever you want the “unchecked” value to be.