ASP.NET Server control error: Unknown server tag

25,750

Should it just be:

<cc1:StandardControl ID="scSomething" runat="server">
</cc1:StandardControl>
Share:
25,750
hermes the goat
Author by

hermes the goat

Updated on August 01, 2022

Comments

  • hermes the goat
    hermes the goat almost 2 years

    This is my first attempt to build an ASP.NET server control. Writing the control code was simple but I've run into a roadblock trying to get the control on a web page.

    I built the control in one project and referenced it in another. In that second project I got the control into the Toolbox and dragged/dropped the control on the page. I can compile the web project without error, but when I browse to the page I get this error:

    Parser Error Message: Unknown server tag 'cc1:StandardControl1'.

    Doing some looking around I see others having this problem for various reasons, but none seem to apply to my situation. One solution was to add the assembly to the register tag, but that isn't an issue with my page:

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="another.aspx.vb" Inherits="Educate.another" %>
    <%@ Register Assembly="ServerControlSandbox" Namespace="ServerControlSandbox" TagPrefix="cc1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <cc1:StandardControl1 runat="server">
            </cc1:StandardControl1>
        </div>
        </form>
    </body>
    </html>
    

    Another solution said to add it to the web.config, again with the assembly attribute. But with this in my web.config I still get the error:

    <controls>
            <add tagPrefix="cc1" namespace="ServerControlSandbox" assembly="ServerControlSandbox"/>
                    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                </controls>
    

    I'm thinking there is something simple I am missing but I see nothing wrong, judging by the examples I've looked at. Does anyone have any ideas? Thanks.

    Also, here is the control code:

    namespace ServerControlSandbox
    {
        [DefaultProperty("Text")]
        [ToolboxData("<{0}:StandardControl1 runat=server></{0}:StandardControl1>")]
        public class StandardControl : WebControl
        {
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string Text
            {
                get
                {
                    String s = (String)ViewState["Text"];
                    return ((s == null) ? "[" + this.ID + "]" : s);
                }
    
                set
                {
                    ViewState["Text"] = value;
                }
            }
    
            protected override void RenderContents(HtmlTextWriter output)
            {
                output.Write(Text);
    
                string block = "<p>Here is some text.</p>";
                output.Write(block);            
            }
        }
    }
    
  • dash
    dash over 12 years
    +1 Yes; there is no control in the namespace ServerControlSandbox with the classname StandardControl1 - this is how the parser works - it looks for the classname after the cc1: prefix in the assembly you specify in the supplied namespace - I bet the IDE has added that for some reason.
  • Kev Ritchie
    Kev Ritchie over 12 years
    Thanks for explanation @dash :)
  • hermes the goat
    hermes the goat over 12 years
    That did the trick -- yes, they 'StandardControl1' was dropped in there by the IDE. I would've banged my head against the wall for a long time looking for that one. Thanks!
  • Nelson Rothermel
    Nelson Rothermel over 9 years
    Old question, but it put StandardControl1 because of the ToolboxData attribute.