Search code examples
c#asp.netuser-controlsvs-web-site-projectvs-web-application-project

Unrecognized element exceptions after conversion to web application


After converting my Web Site Project to a Web Application Project, some of my custom controls are missing, and I keep getting an get unrecognized element exceptions.

I can't figure out what's going on. I've tried copying over the web.config and registering the controls in the page directive, but it's still not working. Do I need to adjust the web.config manually, or is it possible that I'm still missing a reference somewhere?

I would appreciate some advice on how to fix this.


Solution

  • It most likely has something to do with the conversion, and I suspect the application namespace. I don't know how thorough the conversion process is, but you might need to update the user control directives and code-behind files.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="MyNamespace.MyApplication.Controls.MyUserControl" %>
    

    Code-behind:

    namespace MyNamespace.MyApplication.Controls
    {
        public partial class MyUserControl : UserControl
        {
            ...
        }
    }
    

    Also, make sure that the user controls are mapped properly in the web.config:

    <pages>
        <controls>
            <add tagPrefix="Custom" src="~/controls/myusercontrol.ascx" tagName="MyUserControl" />
            ...
        </controls>
    </pages>