asp.net - how to rectreate this dynamic controls -


try make simple application in have dropdown list tems - numbers 1 4.

depending on number user choose - create dynamically number of checkboxes binded checkedchanged event. when user checks of checkboxes checkedchanged event raised , store text of checked checkbox in session , when click button want see text checked checkboxes.

but seems in checkedchanged event handler should recreate dynamic cotrol haven't found solution. thank in advance.

public partial class proba : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {         dd1.items.add("1");         dd1.items.add("2");         dd1.items.add("3");         dd1.items.add("4"); }  protected void dd1_selectedindexchanged1(object sender, eventargs e) {     int numtourists = convert.toint32(dd1.selecteditem.text);      (int = 0; < numtourists; i++)     {         checkbox chk = new checkbox();         chk.id = "chk" + i;         chk.text = "box" + i;           chk.autopostback = true;          chk.checkedchanged += new eventhandler(checkchanged);         page.findcontrol("form1").controls.add(chk);       } }  protected void checkchanged(object sender, eventargs e) {      // here should recteate control      checkbox chk = (checkbox)sender;      lblpr.text += chk.text;      srolession["chk"] = chk.text;   } 

     static bool chkddlchange=false; //define this....to check drop changed or not.     protected void page_load(object sender, eventargs e)         {             dd1.items.add("1");             dd1.items.add("2");             dd1.items.add("3");             dd1.items.add("4");     if(page.ispostback && chkddl==true)     {      int numtourists = convert.toint32(dd1.selecteditem.text);        chkddl=true;//make true can know ddlindex changed..         (int = 0; < numtourists; i++)         {             checkbox chk = new checkbox();             chk.id = "chk" + i;             chk.text = "box" + i;               chk.autopostback = true;              chk.checkedchanged += new eventhandler(checkchanged);             page.findcontrol("form1").controls.add(chk);           }     }     }      protected void dd1_selectedindexchanged1(object sender, eventargs e)     {         int numtourists = convert.toint32(dd1.selecteditem.text);        chkddl=true;//make true can know ddlindex changed..you have  checkboxex on page load         (int = 0; < numtourists; i++)         {             checkbox chk = new checkbox();             chk.id = "chk" + i;             chk.text = "box" + i;               chk.autopostback = true;              chk.checkedchanged += new eventhandler(checkchanged);             page.findcontrol("form1").controls.add(chk);           }     } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -