ASP.NET Custom Control - Unknown server tag
I was receiving the "Unknown server tag" error for a user control that was part of my project. There was no external assembly. @citronas mentioned that "If this does not work, your control probably can't compile.", and that is also listed as the most likely cause in this troubleshooting post.
Although my control code was compiling without errors, it turned out that there were warnings that I was ignoring. My warnings were regarding a resource file that was in my control folder that was referencing another missing file. Once I addressed the warnings, then the control compiled correctly and I was able to use the control with just a Register directive and no modifications to web.config, like this:
<%@ Register TagPrefix="myPrefix" TagName="myControl" Src="~/controls/mySourceFile.ascx" %>
<myPrefix:myControl runat="server"></myPrefix:myControl>
When adding a namespace, I've found I also need the assembly. If your assembly is also myApplication
do this in web.config:
<add tagPrefix="one" namespace="myApplication.Controls" assembly="myApplication"/>
Then, just clean and rebuild and it should all work. Once this is in your web.config, you don't need to add it to your page unless you're using this in a control in the same directory, then you'll need the reference at the top of the web form. But, I recommend against using custom server controls in the same directory as user controls.