dinamically-created checkbox doesn't load it's state

  • Thread starter Michael.Karn.Ivanov
  • Start date
M

Michael.Karn.Ivanov

i have an asp.net application and a page as a part of it. I override
CreateChildControls function and in it i call my function to create
some dinamic controls before base.CreateChildControls().

In my function i create some controls: checkboxes, drop-downlists and
so on.

If i fill this controls with values when page is displayed in browser,
after postback checkboxes lose their values, while other controls not.

I use this code to create checkboxes
private HtmlTableCell CreateCheckboxCell( string controlName, string
displayOption )
{
HtmlTableCell cell = new HtmlTableCell();
CheckBox chb = new CheckBox();
chb.ID = "_" + controlName + "_";
chb.Width = new Unit( "100%" );
if( displayOption == "read-only" ) {
chb.Enabled = false;
}
cell.Controls.Add( chb );
return cell;
}

and, for example, this, to create dropdownlists:

private HtmlTableCell CreateDropdownCell( string controlName, string
displayOption, Dictionary<string, string> values )
{
HtmlTableCell cell = new HtmlTableCell();
DropDownList ddl = new DropDownList();
ddl.ID = "_" + controlName + "_";
ddl.Width = new Unit( "100%" );
if( displayOption == "read-only" )
ddl.Enabled = false;
ddl.Items.Clear();
foreach( KeyValuePair<string, string> pair in values ) {
ddl.Items.Add( new ListItem( pair.Value, pair.Key ) );
}
cell.Controls.Add( ddl );
return cell;
}

i don't see any principal differences between these two methods and i
don't understand why dropdownlists restore their values from form data
and checkboxes don't.

If anybody has any ideas - give me, pls.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top