asp.net c# event handler not working second time -
i have asp.net web page contain panel filled on run time
protected void page_load(object sender, eventargs e) { buildstructure(1); }
and method
public void buildstructure(int level_id) { pmain.controls.clear(); //response.write(@"<script language='javascript'>alert('" + level_id + "');</script>"); datautility du = new datautility(@"****"); datatable dt = du.getdatatable("select * dbo.prstructure_main level_id = "+level_id); int curr_level = 1; int curr_child = 1; int totalchild = 0; if (dt.rows.count > 0) { panel plevel = new panel(); plevel.cssclass = "level"; panel pitem = new panel(); pitem.cssclass = "item-ceo"; label litem = new label(); litem.text = dt.rows[0].itemarray[2].tostring(); pitem.controls.add(litem); plevel.controls.add(pitem); pmain.controls.add(plevel); panel plevelline = new panel(); plevelline.cssclass = "level"; panel pitemline = new panel(); pitemline.cssclass = "item-line-ceo"; panel pline = new panel(); pline.cssclass = "horizontal-line"; pitemline.controls.add(pline); plevelline.controls.add(pitemline); pmain.controls.add(plevelline); panel plevelline2 = new panel(); plevelline2.cssclass = "level"; panel plevel2 = new panel(); plevel2.cssclass = "level"; dt = du.getdatatable("select * dbo.prstructure_main level_parent = "+(convert.toint32( dt.rows[0].itemarray[0].tostring()))); lbitem2 = new linkbutton[dt.rows.count]; (int = 0; < dt.rows.count; i++) { panel pitemline2 = new panel(); panel pline2 = new panel(); if (i == 0) { pitemline2.cssclass = "item-line-level2-first"; pline2.cssclass = "horizontal-line2-first"; } else if (i == dt.rows.count - 1) { pitemline2.cssclass = "item-line-level2-last"; pline2.cssclass = "horizontal-line2-last"; } else { pitemline2.cssclass = "item-line-level2-middle"; pline2.cssclass = "horizontal-line2-middle"; } pitemline2.controls.add(pline2); plevelline2.controls.add(pitemline2); panel pitem2 = new panel(); pitem2.cssclass = "item-level2"; panel pitemcontent2 = new panel(); pitemcontent2.cssclass = "item-level2-content"; lbitem2[i] = new linkbutton(); lbitem2[i].text = dt.rows[i].itemarray[2].tostring(); int current_level1 = (int)dt.rows[i].itemarray[0]; //lbitem2.onclientclick = "alert('" + current_level1 + "')"; //lbitem2.click += new eventhandler((s,e) => evhandler(s,e, current_level1)); lbitem2[i].click += new system.eventhandler(delegate(object o, eventargs a) { evhandler(o, a, current_level1); }); pitemcontent2.controls.add(lbitem2[i]); //plevel.controls.add(lbitem); datatable dt2 = du.getdatatable("select * dbo.prstructure_main level_parent = " + dt.rows[i].itemarray[0]); panel pmenulevel = new panel(); pmenulevel.cssclass = "menu-level2"; //<div class="menu-level2-items"><a href="#">assets integrity management</a></div> (int j = 0; j < dt2.rows.count; j++) { panel pmenulevelitems = new panel(); pmenulevelitems.cssclass = "menu-level2-items"; linkbutton lbmenuitem = new linkbutton(); lbmenuitem.text = dt2.rows[j].itemarray[2].tostring(); int current_level2 = (int)dt2.rows[j].itemarray[0]; //lbmenuitem.click += new eventhandler(delegate (object o, eventargs ee) { evhandler(s, ee,current_level2)}); lbmenuitem.click += new eventhandler(delegate (object o, eventargs a) { evhandler(o, a, current_level2); }); pmenulevelitems.controls.add(lbmenuitem); datatable dt3 = du.getdatatable("select * dbo.prstructure_main level_parent = " + dt2.rows[j].itemarray[0]); panel psubmenulevel = new panel(); psubmenulevel.cssclass = "sub-menu-level2"; // <div class="sub-menu-level2-items"><a href="#"> business application section </a></div> (int k = 0; k < dt3.rows.count; k++) { panel psubmenulevelitems = new panel(); psubmenulevelitems.cssclass = "menu-level2-items"; linkbutton lbsubmenuitem = new linkbutton(); lbsubmenuitem.text = dt3.rows[k].itemarray[2].tostring(); int current_level3 = (int)dt3.rows[k].itemarray[0]; lbmenuitem.click += new eventhandler((s, e) => evhandler(s, e, current_level3)); psubmenulevelitems.controls.add(lbsubmenuitem); psubmenulevel.controls.add(psubmenulevelitems); } pmenulevelitems.controls.add(psubmenulevel); pmenulevel.controls.add(pmenulevelitems); } pitemcontent2.controls.add(pmenulevel); pitem2.controls.add(pitemcontent2); plevel2.controls.add(pitem2); } pmain.controls.add(plevelline2); pmain.controls.add(plevel2); } }
i have problem in section
lbmenuitem.click += new eventhandler((s, e) => evhandler(s, e, current_level3));
and handler method
public void evhandler(object s,eventargs e, int somedata){ //response.write(@"<script language='javascript'>alert('" + somedata + "');</script>"); scriptmanager.registerstartupscript(this.page, this.page.gettype(),"err_msg","alert('" + somedata + "');", true); buildstructure(somedata); }
it work first time
but when click again make page load.
i think page_load
should below
protected void page_load(object sender, eventargs e) { if(!ispostback){ buildstructure(1); } }
Comments
Post a Comment