c# - CheckChanged will not fire -


i trying learn c# , asp.net, , i'm having trouble figuring out checkbox events.

phone class:

public checkbox chkbox { get; set; }  chkbox = new checkbox(); chkbox.checkedchanged += chkbox_checkedchanged;  void chkbox_checkedchanged(object sender, eventargs e) {     throw new notimplementedexception(); } 

default.aspx.cs

foreach (phone p in building.phones) {     tablecell cell_switch = new tablecell();     cell_switch.controls.add(p.chkbox);     row.cells.add(cell_switch); } 

all of checkboxes show in table no issues, when check box cannot code break on checkchanged event. i'm sure i'm misunderstanding fundamental here, appreciated!

notice code changes made default.aspx.cs

    public class building     {         public list<phone> phones { get; set; }         public building()         {             phones = new list<phone>()             {                  new phone(),                 new phone()             };         }     }      public class phone     {        public checkbox chkbox { get; set; }        public phone()        {            chkbox = new checkbox();            chkbox.checkedchanged += chkbox_checkedchanged;            chkbox.autopostback = true;        }         void chkbox_checkedchanged(object sender, eventargs e)        {            throw new notimplementedexception();        }     }      public partial class default : system.web.ui.page     {         building building = new building();         protected void page_init(object sender, eventargs e)         {             if (session["phonecheckboxlist"] != null)             {                 list<checkbox> phonecheckboxlist = session["phonecheckboxlist"] list<checkbox>;                 buildtable(phonecheckboxlist);             }         }          protected void button1_click(object sender, eventargs e)         {             list<checkbox> phonecheckboxlist = new list<checkbox>();             buildtable(phonecheckboxlist);         }          private void buildtable(list<checkbox> phonecheckboxlist)         {             foreach (phone p in building.phones)             {                 tablecell cell_switch = new tablecell();                 cell_switch.controls.add(p.chkbox);                 row.cells.add(cell_switch);                 phonecheckboxlist.add(p.chkbox);             }             if (session["phonecheckboxlist"] == null)                 session["phonecheckboxlist"] = phonecheckboxlist;         }     }     , in global.asax page add following code:          protected void application_acquirerequeststate(object sender, eventargs e)         {             httpcontext context = base.context;             httprequest request = context.request;             string pagename = system.io.path.getfilenamewithoutextension(request.rawurl);             if (pagename != "default")             {                 if (context.session["phonecheckboxlist"] != null)                     context.session.remove("phonecheckboxlist");             }         } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -