determining dynamic checkbox control's Checked value

  • Thread starter Thread starter J
  • Start date Start date
J

J

I'm dynamically adding checkboxes in the Page_Load (regardless of PostBack).
When IsPostBack, the checkboxes display as I expected and their
checked/unchecked status is also as expected. At this point, I want to find
particular checkboxes and determine whether they are check/unchecked, but
the code only returns that all the checkboxes are unchecked.

void SaveModel(Control parent)
{
// spin through controls recursively
foreach (Control c in parent.Controls)
{
if (c.ID != null && c.ID.IndexOf("cbxModel") >= 0)
{
// ? ((CheckBox).c).Text displays the correct value at this
point, BUT.....

//-->> this is not detecting the box checked although it's
clearly checked in the browser
if (((CheckBox)c).Checked == true)
{
//save to db here
}
}
if (c.Controls.Count > 0)
{
SaveModel(c);
}
}
}

Thanks.
 
I'm dynamically adding checkboxes in the Page_Load (regardless of PostBack).
When IsPostBack, the checkboxes display as I expected and their
checked/unchecked status is also as expected.  At this point, I want to find
particular checkboxes and determine whether they are check/unchecked, but
the code only returns that all the checkboxes are unchecked.

void SaveModel(Control parent)
{
    // spin through controls recursively
    foreach (Control c in parent.Controls)
    {
        if (c.ID != null && c.ID.IndexOf("cbxModel") >= 0)
        {
            //  ? ((CheckBox).c).Text displays the correct value at this
point, BUT.....

            //-->> this is not detecting the box checked although it's
clearly checked in the browser
            if (((CheckBox)c).Checked == true)
            {
                   //save to db here
             }
         }
         if (c.Controls.Count > 0)
         {
             SaveModel(c);
         }
     }

}

Thanks.

Hi...

After loading the dynamically created controls in post back ...
asp.net automatically assignes statechanges of the controls...

you have to make sure that you do check your changes after you loading
the dynamically loaded controls...

Md. Masudur Rahman
www.munna.shatkotha.com
 
Back
Top