Question

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?

Was it helpful?

Solution

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>

OTHER TIPS

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.

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.

Could it because you are registering the control twice and intellisense is unable to resolve the reference?

I would exepect that the control should be registered in either a config file or in the page directive

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top