Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 489
Mike McClelland Avatar asked Jan 13 '09 09:01

Mike McClelland


3 Answers

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>
like image 122
Robin Day Avatar answered Nov 09 '22 04:11

Robin Day


It probably has to do with the fact that it isn't registered in the main web.config file. Test it out by putting one or two references in the main web.config file.

like image 1
Al W Avatar answered Nov 09 '22 04:11

Al W


I tried your sample code and Intellisense works in both the code view of the aspx page and the code behind page. You might check the class names of your user controls, visual studio includes the folder name in the class name by default. So your control may be named CommonControls_Foo instead of Foo as you would expect.

Either way the web.config file has nothing to do with the Intellisense of the code behind. Check the name and namespace of the class.

like image 1
Seth Reno Avatar answered Nov 09 '22 05:11

Seth Reno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!