determining dynamic checkbox control's Checked value

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.
 
M

Masudur

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top