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

3.4k Views Asked by At

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'

2

There are 2 best solutions below

0
On BEST ANSWER

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.

1
On

You either need to put the control into a DLL named "currentwebsitename.dll" (if you want it to work the second way) or you need to specify the source via the src attribute (if you want to do it the first way):

<add tagPrefix="cc1" namespace="mynamespace" src="app_code/control_name_here"/>

Try reading over these two articles as well:

http://msdn.microsoft.com/en-us/library/sbz9etab.aspx and

http://msdn.microsoft.com/en-us/library/yhzc935f.aspx