dynamically created controls and postback
        Posted  
        
            by Mark
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mark
        
        
        
        Published on 2010-05-23T22:18:52Z
        Indexed on 
            2010/05/23
            22:20 UTC
        
        
        Read the original article
        Hit count: 312
        
Hi all,
I have created dynamic controls (Radiobuttonlists) in an asp.net page (c#). I create them after a button click like this.
RadioButtonList rbl = new RadioButtonList();
c2.Controls.Add(rbl);
//Set properties of rbl 
rbl.RepeatLayout = RepeatLayout.Flow;
rbl.ID = string.Format("rbl{0}", item.QuestionID);
rbl.RepeatDirection = RepeatDirection.Horizontal;
rbl.Items.Add(new ListItem("True", "1"));
rbl.Items.Add(new ListItem("False", "0"));
rbl.Items.Add(new ListItem("?", "-1"));
Now the problem arises when I click the submit button, the controls are lost. I know it's better to actually put the controls in page_init event. but is there no workaround so I can still initiate my controls after button click?
And is it good to first create button, then add it to control collection and then set its properties?
Thankd in advance Kind regards, Mark
© Stack Overflow or respective owner