How to add automatically add namespaces to .aspx pages.
Like many of my blog posts, this one is because I solved a frustration today and wanted to share. I have always been a code-behind type guy. I liked having my code seperate from my presentation...whatever.
With Studio 2005, there was the 'magical' addition of the Resolve context menu item, and the much improved the intellisense parsing for code-inline aspx pages. When dealing in true .cs only files I begin typing my Type I'm looking for, if it doesn't pop in intellisense to get the quick space for completion, I carefully type out the real Class name and case it properly. Then I hit my Context Menu shortcut key type 's' and hit enter twice. 'using System.Collections.Generics' pops at the top for future use with zero time lost.
However in the code inline world, if you use the Resolve feature, it will complete the namespace name only on that instance you are typing. It won't automatically add the page directive to get the same effect as using.
<%@ Import Namespace="BillRob.WebControls" %>
I've always been frustrated by the fact the Resolve doesn't work as well as I'd like for code-inline pages. You can automatically add namespaces to your pages by making a modification to your web.config. If you are like me, you have sections of your config file you move between projects. You can add a section to your web.config under system.web/pages/namespaces
<pages validateRequest="false" enableSessionState="false" enableEventValidation="false" autoEventWireup="true" pageBaseType="CommunityServer.Components.CSPage, CommunityServer.Components">
<namespaces>
<add namespace="BilRob.WebControl"/>
<add namespace="CommunityServer.Components"/>
</namespaces>