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?
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With