Error using Themes to Skin Custom Controls in ASP.NET

I recently ran across a problem while trying to register a custom ASP.NET control on a themed page.  First I modified web.Config to register an assembly for use on any page or control in the site (take note of the namespace):

<system.web>
   <controls>
      <add namespace=”Insight.Web.CustomControls” tagPrefix=”custom” assembly=”Insight.Web”/>
   </controls>
</system.web>

Next, I created a theme named Insight and registered it site-wide in web.Config:

<system.web>
   <pages masterPageFile=”~/default.Master” styleSheetTheme=”Insight“>
</system.web>

Note that first segment of the namespace (Insight) matches the name of the Theme.  This will cause an error:

“Type Insight.Web.CustomControls.GridView is not defined”.

The type was defined just fine thank you very much, ASP.NET gets confused because part of the type name matches the name of the theme.  But you can fix this easily by just changing the name of the theme from Insight to something else (like InsightTheme):

<system.web>
   <pages masterPageFile=”~/default.Master” styleSheetTheme=”InsightTheme“>
</system.web>

And presto! No more error.  It’s best to set the default theme once in web.Config instead of on each page, making problems like this much easier to fix!

Leave a Reply