mercredi 25 mai 2016

Checkbox is not checked on postback ASP NET

I have a asp.net project where I have, lets call them objects. All objects are created in a repeater:

<section class="topbar">
    <asp:Button runat="server" ID="btnSave" OnClick="btnSave_OnClick" Text="Save" />
</section>

<asp:Repeater runat="server" id="gwList">
    <ItemTemplate>
        <div class="block">
            <input type="checkbox"  runat="server" ID="chkObjectSelected" value='<%# ((Object.Object)Container.DataItem).Id %>'/> 

            <label><%# ((Object.object)Container.DataItem).Title %></label>

        </div>
    </ItemTemplate>
</asp:Repeater>

Here comes the problem, none of the selected objects will be set as selected in the postback. Heres the code i use to determine if the objects are checked:

protected void btnSave_OnClick(object sender, EventArgs e) {

List<string> objectIdSelected = new List<string>(); 

foreach (RepeaterItem oneObject in gwList.Items)
{
    HtmlInputCheckBox chkObj = (HtmlInputCheckBox)carAd.FindControl("chkObjectSelected");

    if (chkObj.Checked)
    {
        objectIdSelected.Add(chkObj.Value.ToString());
    }
}

}




Aucun commentaire:

Enregistrer un commentaire