Dynamically loading Web User controls

I have been loading controls dynamically for quite a while, in 1.1, in 2.0 dynamically loading webusercontrols has changed slightly, I remember doing it a while ago but I could not locate the code and could not remember how I did it.

After searching the web I finally found it. So I decided to document it here, in case I need it again.

in .NET1.x we used to load a control and call its method by:

dim ctl as new MyControl

ctl.PopulateFields(ID)

PlaceHolder1.controls.add (ctl)

in .NET2.0

 

Ctl = LoadControl(

 

PlaceHolder1.controls.add(ctl)

"~/Controls/MyControl.ascx")Ctl.PopulateFields(ArControls(i))
Dim Ctl As ASP.controls_MyControl_ascx

Comments

# re: Dynamically loading Web User controls
Gravatar Let me shoot my load in your face Shervin!!
Left by Dave Noderer on 6/10/2007 11:34 PM
# re: Dynamically loading Web User controls
Gravatar Hi,

I am facing problem while working with ASCX page.I am loading the ascx page dynamically by ckicking on the button in aspx page.The page is getting loaded.But whwn i am clicking the button in ascx page it is not getting fired ,But the problem is not occuring whwn i loads the ascx page in page load of aspx page.Please provide a solution for this

Thanks in advance


Left by Sri on 10/18/2007 2:32 AM

Leave Your Comment

Title*
Name*
Email (never displayed)
 (will show your gravatar)
Url
Comment*

 

Preview Your Comment.