Cally K

Cally K

  • 1.2k
  • 507
  • 15.6k

Unable to uncheck a checkbox at first click

Jan 23 2019 6:34 PM
Hi,
I am not able to uncheck a checkbox at first click, on the second click it works fine. I am pretty new to .Net and this is my first time facing it, checking the checkboxes works fine with no issue. I am not able to debug as unchecking the checkbox does not even trigger a page refresh or the event attached to it. This is my code. Please help. 
  1. protected void CheckBox1_CheckedChanged(object sender, EventArgs e)  
  2.         {  
  3.             //List<string> user_select_weeks_list = new List<string>();  
  4.             AllLists create1 = new AllLists();  
  5.   
  6.             for (int i = 0; i < rptItemsInCart.Items.Count; i++)  
  7.             {  
  8.                 CheckBox ref_to_checkBox = (CheckBox)rptItemsInCart.Items[i].FindControl("Checkbox1");  
  9.                 if (ref_to_checkBox.Checked)  
  10.                 {  
  11.                     Ok_prompt_to_upload_Button.Visible = true;  
  12.                     ref_to_checkBox.ID = "Week" + (i + 1);  
  13.                     Label2.Text = ref_to_checkBox.ID;  
  14.                     create1.user_select_weeks_list.Add(ref_to_checkBox.ID);  
  15.                    
  16.                     //user_select_weeks_list.Add(ref_to_checkBox.ID);  
  17.                 }  
  18.                 else  
  19.                 {  
  20.                     create1.user_select_weeks_list.Remove(ref_to_checkBox.ID);  
  21.                 }  
  22.             }  
  23.             selected_weeks_repeater.DataSource = create1.user_select_weeks_list;  
  24.             selected_weeks_repeater.DataBind();  
  25.   
  26.         }  
  1. public class AllLists  
  2.    {  
  3.        public List<string> user_select_weeks_list { getset; }  
  4.   
  5.        public AllLists()  
  6.        {  
  7.            user_select_weeks_list = new List<string>();  
  8.        }  
  9.    }  
I don't have anything in my page load, am I missing something.

Answers (2)