Namespaces in ASP.NET and Referencing Controls

Posted Tuesday, May 24, 2005 10:14 AM by C-Dog's .NET Tip of the Day
Today's article is particularly important because if you don't know this you will have trouble getting controls to work in ASP.NET 2.0.  As I have mentioned in the past Web Applications do not use namespaces any longer.  Any class placed in the App_Code folder can be used globally throughout the web site.  This does not include controls.  A control can now no longer see another control unless a reference has specifically been added in the markup to that control (even if it is in the same folder).  This is a bad time and I have been complaining a lot to Microsoft about it. 
 
For example, if you have the VehicleDetails control and you want to load the VehicleDetailsSubControl at runtime, you must incude a reference such as the following in your markup.
 
<%@ Register Src="vehicledetailssubcontrol.ascx" TagName="vehicledetailssubcontrol" TagPrefix="uc6" %>
In this case, I don't think that the TagName and TagPrefix are required since the control is loaded at runtime.  If the above line is not included, the control will not show up in IntelliSense even if you manually include a namespace.  It will not compile.
 
This also applies when inheriting from a control.  If you want to inherit from the BaseControl, you must include a register directive for it to compile.
 
Unfortunately, the Migarion Wizard does not currently add these register directives automatically.  However, after talking to Scott Guthrie, they may be taking care of this for us.

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=120