Element is not a known element warning in Visual Studio when using User controls

后端 未结 7 1685
深忆病人
深忆病人 2021-01-03 21:04

I have a Visual Studio 2008 project that is showing the following warning when using User Controls, and I haven’t been able to find a solution anywhere.

相关标签:
7条回答
  • 2021-01-03 21:46

    Check you might be on ContentPlaceHolderID="MainContent" on Asp.net, so place the code on a new placeholder

    0 讨论(0)
  • 2021-01-03 21:47

    I found that the issur was resolved when I changed the Build Action from "content" to "compile" for the .ascx file and afterwards chaned it back.

    0 讨论(0)
  • 2021-01-03 21:51

    This sounds like a classic re-build your solution and "close and re-open Visual Studio" problem.

    It's possible it may also be related to a similar problem I had which I answered at Resolving "Validation (): Element ‘xxxx’ is not supported" warning in Visual Studio 2005/2008.

    0 讨论(0)
  • Apparently this can also happen if the Namespace name in the .ascx file doesn't match the namespace in the ascx.cs (codebehind) file. Just one more issue to check.

    0 讨论(0)
  • 2021-01-03 22:02

    This can also occur if the element you're trying to add is within the tags of another element that it shouldn't be within.

    For Example:

    <asp:Button ID="button" runat="server" >
        <asp:Repeater ID="repeater" runat="server"></asp:Repeater>
    </asp:Button>
    

    Or in my case, placing an <asp:Repeater> in an <asp:UpdatePanel> and forgetting to put it in the <ContentTemplate>:

    <asp:UpdatePanel ID="upPanel" runat="server">
        <ContentTemplate>
            <asp:Repeater ID="rep" runat="server">
    
            </asp:Repeater>
        </ContentTemplate>
    </asp:UpdatePanel>
    
    0 讨论(0)
  • 2021-01-03 22:07

    From the OP:

    The apparent solution to this is to make sure that the TagName is the name of control class.

    So for my example, the following displayed the warning:

    <%@ Register Src="~/path/to/Control.ascx" TagName="tagName" TagPrefix="tagprefix" %>
    

    <tagprefix:tagName runat="server" id="controlID" />

    But changing it to:

    <%@ Register Src="~/path/to/Control.ascx" TagName="Control" TagPrefix="tagprefix" %>
    

    <tagprefix:Control runat="server" id="controlID" />

    fixes it.

    0 讨论(0)
提交回复
热议问题