Dynamically adding usercontrols

G

Guest

I'm quite new to ASP.NET so please forgive me if this is a silly question but
I'm completely stuck!

I'm trying to dynamically add a UserControl to a web form. My control is in
a file called Customers.ascx so I'm using:

Dim myControl as UserControl
myContol = LoadControl("Customers.ascx")

I then want to assign a value to the CustomerID property of the control but,
obviously, becasue the variable is of type UserControl there is no CustomerID
property.

What type should the myControl variable be? Or am I going about this
completely wrongly?

I'm using VB.NET in Visual Studio 2003, if that makes any difference.

Any help you can give would be greatly appreciated.

Alan
 
K

Karl

You are going about it correctly. What type it should be is the type of the
control..which, my guess is Customer

If you go into your codebehind, you'll see something like

Public Class Customer
Inherits UserControl
...



So...

Dim myControl as Customer
myControl = ctype(LoadControl("Customer.ascx", Customer)
myControl.CustomerId = 123

Karl
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top