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

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,
 
D

dunshRB

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top