[ASP.net / C#] Checkbox Checked Always false

  • Thread starter Thread starter Eric via .NET 247
  • Start date Start date
E

Eric via .NET 247

Hello,

I'm dynamicly filling a table with checkboxes, doing this:

...
CheckBox chkBox = new CheckBox();
chkBox.ID = "chk" + i.ToString();
chkBox.AutoPostBack=true;
...

As you can see I create Checkboxes with ID's like: chk0, chk1, chk2 etc.

When I select one (or more) checkboxes the page reloads as it should.
However, when I try to read the properties of the checkboxes:

for (int i = 0 ; i < /*number_of_items */ ; i++)
{
CheckBox c = (CheckBox)FindControl("chk"+i.ToString());

Response.Write(c.ID); // This shows "chk0, chk1, chk2 etc."
Response.Write(c.Checked); // This shows FALSE(!) every time, even when it's selected

}

Somehow he doesn't store the checked-value (true)

When the page reloads (after selecting a checkbox) the checkbox keeps selected, as it shoulds.

Can anyone help me?

Greetingz,
 
Where are you creating the checkboxes (what event). If you move it to
the onInit event it should fix your problem.
 

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

Back
Top