I have code to generate check box list dynamically according to some conditions, If check box selected will be disabled vs.
After that will add this check box list control to placeholder in update panel,
Problem doesn't occur at the first time but when i update the criteria to add or remove from check box list , some check boxes disabled but not selected
ASPX Code
<asp:TextBox AutoPostBack="true" ID="txtCount" runat="server" OnTextChanged="txtCount_TextChanged">0</asp:TextBox> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:PlaceHolder runat="server" ID="ph"></asp:PlaceHolder> </ContentTemplate> </asp:UpdatePanel>
C# Code
protected void Page_Load(object sender, EventArgs e) { CheckBoxList ckb = new CheckBoxList(); int maxCount = int.Parse(txtCount.Text); for (int i = 0; i < maxCount; i++) { ListItem li = new ListItem(); li.Text = "CheckBox " + i.ToString(); bool selected = (i % 2 == 0); li.Selected = selected; li.Enabled = !selected; ckb.Items.Add(li); } ph.Controls.Add(ckb); } protected void txtCount_TextChanged(object sender, EventArgs e) { }