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