R – Visual Studio 2008 user controls registered in the web.config not registering with intellisense

asp.netintellisenseuser-controlsvisual-studio-2008

I have a C# Web application built in Visual Studio 2008 where we rely heavily on user controls for 'pre-built' blocks of ASP.NET.

Instead of registering a big stack of user controls on each page, we register all the controls in a local (to a specific folder) web.config file. The advantage is that we can use the controls and the pages look 'cleaner' in source view. However, neither the VS2008 Design view nor Intellisense recognize the fact the controls are registered in web.config. However, the application itself works as expected.


Normally at the top of each page we'd have a tag like this:

<%@ Register src="~/CommonControls/Foo.ascx" tagname="Foo" tagprefix="Bar" %>

And we register the controls in a local web.config like so:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <pages>
            <controls>
                <add src="~/CommonControls/Foo.ascx" tagName="Foo" tagPrefix="Bar"/>
            </controls>
        </pages>
    </system.web>
</configuration>

Does anyone know of a fix for getting Intellisense to recognize these custom controls? Or, is there a 'better' way of doing this?

Best Answer

Whilst this doesn't work in a local Web.Config file you can use the Location tag in your root web.config file to achieve the same result.

For example:

<?xml version="1.0"?>
<configuration>
    <location path="MyPath">
        <system.web>
            <pages>
                <controls>
                    <add src="~/CommonControls/Foo.ascx" tagName="Foo" tagPrefix="Bar"/>
                </controls>
            </pages>
        </system.web>
    </location>
</configuration>