Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > dinamically-created checkbox doesn't load it's state

Thread Tools

dinamically-created checkbox doesn't load it's state
Posts: n/a
i have an 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;
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.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASPNET CheckBox and a CheckBox in a TemplateField Jason Huang ASP .Net 0 06-29-2007 12:35 AM
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
disable checkbox list checkbox Vikram ASP .Net 1 01-25-2006 02:59 PM
Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked. Joey Pang ASP .Net Datagrid Control 4 06-13-2005 02:29 AM
Text on Checkbox below the checkbox tshad ASP .Net 0 04-14-2005 11:26 PM