Dynamically Load Control from Control Library

S

ShaunN

I have created a number of web user controls within a Web Control Library called Blain.UQR.WebControls.

I have a separate ASP.NET Web Application in which I want to use these controls. A reference to the Blain.UQR.WebControls dll is included in my ASP.NET Web Application project.

The problem is that I cannot figure out how to dynamically load controls from the Blain.UQR.WebControls library.

Of course, the standard way of dynamically including a user web control into a page is to use the LoadControl method. However, this takes the file name of the control as a parameter. For example:

Dim ctl as Control
ctl = LoadControl("/UserControls/myusercontrol.ascx")

Since the web user controls are simply included in the project via a Reference to the Blain.UQR.Webcontrols dll, I do not know how I am supposed to dynamically load them, since the .ascx files are not available.

Could anyone suggest how this might be done?

Thanks a lot,
Shaun
 
C

Cy Huckaba

Hey Shaun,

At this point what you have is a class that you have to instantiate and add to
the page that you are working with.

Basically, it should work like any other object. I would use a place holder
control on the page that you will be adding the control to. Something like this.

dim ctrl as New Blain.UQR.Webcontrols.ControlType

'set props here if needed

(placeholderid).controls.add(ctrl)

That's it. That should do it.

Cy Huckaba
Austin, TX


ShaunN said:
I have created a number of web user controls within a Web Control Library called Blain.UQR.WebControls.

I have a separate ASP.NET Web Application in which I want to use these
controls. A reference to the Blain.UQR.WebControls dll is included in my ASP.NET
Web Application project.
The problem is that I cannot figure out how to dynamically load controls from
the Blain.UQR.WebControls library.
Of course, the standard way of dynamically including a user web control into a
page is to use the LoadControl method. However, this takes the file name of the
control as a parameter. For example:
Dim ctl as Control
ctl = LoadControl("/UserControls/myusercontrol.ascx")

Since the web user controls are simply included in the project via a Reference
to the Blain.UQR.Webcontrols dll, I do not know how I am supposed to dynamically
load them, since the .ascx files are not available.
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top