asp.net - Load a dynamic custom user control added during page execution (button click event) -


i'm trying add custom control panel (containing "form" input data) during button click event , want access it's methods .validate() after data has been inputted. when try ctrl comes null value.

here's part of code :

protected void btnnext2_click(object sender, eventargs e) {  ... ctrlcompliance = (compliance)loadcontrol("../../ascx/srm/compliance.ascx"); ctrlcompliance.readonly = false; pnlcompliance.controls.add(ctrlcompliance); ... }  protected void btnnext3_click(object sender, eventargs e) {  ... ctrlcompliance = pnlcompliance.controls[0] compliance; ctrlcompliance.validate() <- allways null ... } 

i cannot use page_init of solutions propose , need load during button click. did had same problem me?

you should load anyway using page_init, set visible property false. using javascript or code-behind can change visible property true when need show print button.

so move:

ctrlcompliance = (compliance)loadcontrol("../../ascx/srm/compliance.ascx"); ctrlcompliance.readonly = false; pnlcompliance.controls.add(ctrlcompliance); 

to page_init


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -