4

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);            
        }
    }
}

1 Answer 1

7

Should it just be:

<cc1:StandardControl ID="scSomething" runat="server">
</cc1:StandardControl>
Sign up to request clarification or add additional context in comments.

3 Comments

+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.
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!
Old question, but it put StandardControl1 because of the ToolboxData attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.