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

Discussion in 'ASP .Net Web Controls' started by Michael.Karn.Ivanov@gmail.com, Aug 22, 2006.

  1. Guest

    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.
     
    , Aug 22, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rafi
    Replies:
    0
    Views:
    379
  2. Leonardo Gangemi
    Replies:
    0
    Views:
    334
    Leonardo Gangemi
    Apr 7, 2004
  3. =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=

    Dinamically created webcontrol does not fire events

    =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=, May 24, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    400
    =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=
    May 25, 2007
  4. Fabiano

    How to read listbox values created dinamically

    Fabiano, Jun 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    131
    Fabiano
    Jun 25, 2004
  5. Replies:
    2
    Views:
    100
Loading...

Share This Page