web user control

  • Thread starter Thread starter Kevin Attard
  • Start date Start date
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?
 
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.
 
Back
Top