web user control

K

Kevin Attard

Hi there,

i'm using asp.net 2.0 and vs2005.

I am trying to load a usercontrol dynamically when a button is pressed

myUserControl ctl = (myUserControl)Page.LoadControl("myUserControl.ascx");

myUserControl is in the same project but the following error is being thrown
The type or namespace name 'myUserControl' could not be found (are you
missing a using directive or an assembly reference?)

Why isn't the control being found?
 
M

Mark Fitzpatrick

The first thing you can try is ensuring that you have a using directive in
the code behind that references the namespace the user control is in. Just
because a control is in a project doesn't mean it can always be found. You
often have to add a proper using directive just as if it was another
namespace such as System.Data.Common.

If it's in a different directory and you're using the standard web site
project you may not be able to see this control. All the files in a
directory become indepedently compiled instead of the way they were in VS
2003 where everything was compiled into one dll for the whole project. That
means that dlls in seperate directories may not be able to reference
eachother. There is a Web Application Project add-in at www.asp.net under
the downloads section that enables you to create a new web application
project in VS 2005 that's similar to the one in VS 2003.
 

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,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top