简体   繁体   中英

ASCX.cs code behind page not pulling value from the ascx page

I have a checkbox that resets itself on postback to the code behind page, I'm now trying to set the value of the checkbox in the code behind page. But I am unable to do so below is my code the hidden field doesn't get set, any help would be appreciated:

ASPX

    <asp:Checkbox id="HiddenDossetCheckValue" value="" runat="server" type="hidden"/>

function DossettesSet()
    {
    var zCheckBox = document.getElementById('<%=HiddenDossetCheckValue.ClientID%>');


    var checkBoxBool = zCheckBox.checked;


        if(zCheckBox.checked === true)
        {
            document.getElementById('<%=HiddenDossetCheckValue.ClientID%>').value = "1";
            console.log(document.getElementById(HiddenDossetCheckValue).value);
        }

        if (zCheckBox.checked === false) {

            document.getElementById('<%=HiddenDossetCheckValue.ClientID%>').value = "0";
            //console.log(document.getElementById(HiddenDossetCheckValue).value);
        }

    }

ASCX.CS

 public string CheckBoxValue
    {
        get
        {
            bool hiddenField;
            hiddenField = HiddenDossetCheckValue.Checked;
            if (ViewState["HiddenDossetCheckValue"] != null)
                return (string)ViewState["HiddenDossetCheckValue"];
            else
                return null;               
        }
        set
        {
            bool hiddenField = false;
        }
    }

You are assigning the checkbox field to a variable and not using it?

Why not just:

zCheckBox.value = '1';
console.log(zCheckBox.value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM