c# - Asp.net: Page won't refresh after clicking dynamically generated Button controls -
clicking on of dynamically generated button controls indeed call b_click method , delete given user, however, upon deleting page not reload 'new' list of users.
protected void page_load(object sender, eventargs e) { dbdb db = new dbdb(); list<user> users = db.getusers().executetypedlist<user>(); foreach (user u in users) { button b = new button(); b.text = u.firstname; b.click += new eventhandler(b_click); placeholder1.controls.add(b); } } } void b_click(object sender, eventargs e) { button b = (button)sender; dbdb.user.delete(x => x.firstname == b.text); }
protected void page_load(object sender, eventargs e) { loadusers(); } void b_click(object sender, eventargs e) { button button = (button)sender; string firstname = button.commandargument; dbdb.user.delete(x => x.firstname == firstname); placeholder1.controls.remove(button); } void loadusers() { dbdb db = new dbdb(); list<user> users = db.getusers().executetypedlist<user>(); foreach (user user in users) { button button = new button(); button.commandargument = user.firstname; // user "id" identify user. button.text = user.firstname; button.click += new eventhandler(b_click); placeholder1.controls.add(button); } }
Comments
Post a Comment