Search code examples
asp.netweb-configcustom-server-controls

How do I add a reference to a server control in my current website to the web.config


I have extended a server control (not a user control) and put the code in my app_code folder. I would like to add a tag prefix to the web config, but

<add tagPrefix="cc1" namespace="mynamespace" />

and

<add tagPrefix="cc1" namespace="mynamespace" assembly="currentwebsitename" />

don't work. I get this error: Error 147 Unknown server tag 'cc1:Control'


Solution

  • To register server controls that are in the App_Code folder, you only need the tag prefix and namespace. So in web.config it would look like this...

    <add tagPrefix="cc1" namespace="mynamespace"/>
    

    And in a page it would look like this...

    <%@ Register TagPrefix="cc1" Namespace="mynamespace" %>
    

    One gotcha to watch out for is that by default web site projects don't include any namespace at all when you add a new item to the App_Code folder, so you'll need to explicitly make sure your controls have a namespace.