views:

238

answers:

2

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'

+1  A: 

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

Matt Ball
The src attribute is only for user controls, which can't live in the App_Code folder. If you try to use anything in the App_Code folder in the src attribute you get the following error: The file '/Web/App_Code/CustomServerControl.cs' is in the special directory 'App_Code', which is not allowed.
John Clayton
John is right, it does give that error.
+1  A: 

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.

John Clayton