c# - Adding Dynamic Controls to Web Forms -


i trying add new dynamic controls on button click not adding multiple labels, want retain state of control after postback adding textbox typed in value should there.

public partial class _default : system.web.ui.page {   list<string> controlids = new list<string>();   static int count = 0;   protected override void loadviewstate(object savedstate)   {     base.loadviewstate(savedstate);     controlids = (list)viewstate["controlsid"];     foreach (string id in controlids)     {       count++;       label dynamic_typeinerror = new label();       dynamic_typeinerror.id = id;       tablerow tbl_rows = new tablerow();       tablecell tbl_cell = new tablecell();       tbl_cell.controls.add(dynamic_typeinerror);       tbl_rows.cells.add(tbl_cell);       plc.controls.add(tbl_rows);     }   }    protected void bt_adddynamiccontrols_click(object sender, eventargs e)   {     count++;     label dynamic_typeinerror = new label();     dynamic_typeinerror.id = "dynamic_typeinerror" + count;     dynamic_typeinerror.text = "type in error";     tablerow tbl_rows = new tablerow();     tablecell tbl_cell = new tablecell();     tbl_cell.controls.add(dynamic_typeinerror);     tbl_rows.cells.add(tbl_cell);     plc.controls.add(tbl_rows);     controlids.add(dynamic_typeinerror.id);     viewstate["controlsid"] = controlids;   } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -