Loading controls dynamically + passing parameters

J

Jill Graham

Hi,

I can use following syntax to add user controls directly to my pages :
<XYZ:myControl parameter1="value1" parameter2="value2" runat="server" />
The control "myControl" is executed using the supplied parameters parameter1
and parameter2

Now my question :
I've found two ways to add controls dynamically to my page :

method 1
---------
page.loadControl("<.ascx file>")

method 2
---------
activator.createInstance(type.getType("<class name>", true))

The problem is : how can I pass the parameters parameter1 and parameter2 to
the control ?


Thanks for any advice
Jill
 
J

Jim Corey

Jill,

I'm not familiar with the first technique you mention.

But for loading dynamically the control should have properties to hold
the values for parameter1 and parameter2.

Then in the code for the page have a variable for the user control.

dim lControl as MyControl
lControl = LoadControl("MyControl.ascx")
page.Controls.Add(lControl)
lControl.parm1 = someValue


HTH,
Jim
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top