Accessing UserControls programmatically

J

Janaka

I'm not using Visual Studio.NET so I'm not able to find anything on how to
do this by hand. Basically I want to reference a UserControl in my aspx
page's .CS class file. Whenever I do this though I keep getting a
compilation error that the type or namespace name cannot be found. I have
strongly named my control using ClassName="MyControl".

Does anyone have any tips or know of a good article on how to do this?

Thanks,

J
 
J

Jack David

Have you tried this

Control c1 = LoadControl("Read_Text_1.ascx");

Page.Controls.Add(c1);
 
J

Janaka

Yes this is exactly what I have done and doing so works. However if I try
to cast it to a specific type it then throws and error saying the type or
namespace name cannot be found. For example: MyControl mc =
(MyControl)LoadControl("Controls/MyControl.ascx");

I need to cast it so that I can programmatically assign values to the
properties of the control.

J
 
J

John Saunders

Janaka said:
Yes this is exactly what I have done and doing so works. However if I try
to cast it to a specific type it then throws and error saying the type or
namespace name cannot be found. For example: MyControl mc =
(MyControl)LoadControl("Controls/MyControl.ascx");

So, you need to find the type or namespace name.

Look into MyControl.ascx.cs. What namespace does it use, and what class is
declared?
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top