Dynamically Loading User Controls

B

B. Suitt

In ASP.Net 1.1 dynamically loading user controls was very simple, however
with the 2.0+ framework I apparently can not use the same code to accomplish
the same thing and I have not found any examples of how to make it work.

My example code is as follows:

Dim MyControl As Web.UI.Control

MyControl = LoadControl("testcontrol.ascx")
PlaceHolder1.Controls.Clear()
MyControl.ID = "CurrentControl"
PlaceHolder1.Controls.Add(MyControl)

The control will display properly on the screen using the above code,
however if I click on a button that resides inside of the user control, no
event is fired and the control itself just disappears. For the project that
I am working on, it's not an option to load potentially 50 user controls and
just hide and display them. I really need to be able to load them
dynamically.

I'm sure lots of people have encountered this problem by now and no doubt
have the solution. Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top