How to go through CheckBox in WebForms automatically generated with JQuery

1

How to go through several CheckBox in the Click event of a button with C # and these CheckBoxes were automatically generated with JQuery? Home The HTML of the automatically generated CheckBox is this:

<div class="col-md-12">
    <div id="MainContent_pnlCheckbox">
        <div id="MainContent_divCheckboxes">
            <div>
                <a>
                    <input type="checkbox" name="chkCI" id="2" runat="server" checked="checked" value="2">
                        <span>CI 2</span>
                </a>
            </div>
            <div>
                <a>
                    <input type="checkbox" name="chkCI" id="4" runat="server" checked="checked" value="4">
                        <span>CI 4</span>
                </a>
            </div>
        </div>
    </div>
</div>

The code to go through the CheckBox is ess:

foreach(Control item in divCheckboxes.Controls)
{
    if(item is CheckBox)
    {
        CheckBox c = item as CheckBox;
        if (c != null && c.Checked)
        {
            CIModel ci = new CIModel();
            ci.idci = int.Parse(c.ClientID);
            lCI.Add(ci);
        }
    }
}

But the above code does not find the CheckBox object:

Note: I am using a MasterPage.

    
asked by anonymous 23.11.2018 / 13:26

1 answer

0

If they were generated in JQuery or simply added to html, they only exist on the client screen and not on your server. This is not server side components that were rendered by ASP.NET and you will not be able to interact with them in C # like the other controls.

But you can retrieve the selected values through Request.Form

var chkCI = Request.Form.GetValues("chkCI");
    
26.11.2018 / 17:16