asp.net - Adding user control to a place holder on form not working on second postback -


hi have user control loading in place holder , showing on button click, first time working fine, if click on button again code getting executed user control not showing please

protected void btn_click(object sender, eventargs e)     {         placeholder.controls.clear();         usercontrol1 usrcntrl= (usercontrol1)loadcontrol("~/usercontrol.ascx");         placeholder.controls.add(usrcntrl);     } 

you need reacreate dynamic control on every postback same id before , in page_load @ latest.

truly understanding dynamic controls

here's possible implementation store number of created controls via viewstate: find control @ runtime

q: want add 1 or multiple of control? a: 1 user control 

you have recreate control anyway. recommend use static control make visible. that's less complicated, more readable , more efficient since asp.net can handle viewstate of declarative controls better.

truly understanding viewstate


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -