My control is "not allowed here because it does not extend class 'System.Web.UI.UserControl'"
Asked Answered
C

3

17

So I have another noodle-scratcher (for me anyway).

I'm trying to create my own custom control in a CMS I only have partial source code for (i.e. samples the vendor has supplied to me). Basically I have created a class called DataDefinitionContent which extends ControlBase. Now, from what I can garner from the metadata, ControlBase extends UserControl, so I would have thought this would run without a drama. Can anyone shed any light on why this might not be working for me?


My Class:

public partial class DataDefinitionContent : ControlBase, ICustomControl<DataDefinition>
{
... Stuff
}

ControlBase:

using System;
using System.Web.UI;
namespace CMS.Web
{
    public class ControlBase : UserControl
    {
    ... Stuff
    }
}

My ascx file:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DataDefinitionContent.ascx.cs"
    Inherits="CMS.Admin.WebUI.CustomControls.DataDefinitionContent, CoA.Admin.WebUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" %>

The error I'm getting:

Parser Error Message: 'CMS.Admin.WebUI.CustomControls.DataDefinitionContent, CoA.Admin.WebUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not allowed here because it does not extend class 'System.Web.UI.UserControl'.

Line 1: <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DataDefinitionContent.ascx.cs"

Clumsy answered 3/11, 2009 at 6:4 Comment(3)
Is your partial class inside a namespace?Scantling
Actually, no it isn't. Can you give me a clue as to how I would go about deciphering which namespace I should put it in? (OP is still a newbie)Clumsy
well you have ="CMS.Admin.WebUI.CustomControls.DataDefinitionContent, CoA.Admin.WebUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" in your Inherits which I don't think you need. The namespace looks like CMS.Admin.WebUI.CustomControls, though controlbase looks like its in CMS.WebScantling
S
13

Try putting your partial class in

namespace CMS.Web 
Scantling answered 3/11, 2009 at 6:21 Comment(3)
Your suggestion worked, but I ended up approaching the problem from a different angle. Thanks for your help.Clumsy
Cool man. What approach did you take? The whole namespace issue can become an utter nightmare if you ever convert a WebSite to Web Application.Scantling
More specifically the 'designer' file doesn't always generate with the proper namespace. Updating it to have the right namespace fixes the issue.Edla
S
7

I was getting this error when the name of the class that was extending the UserControl class was not the name used in ASP inclusion. I made the change to the class name and redeployed the solution. The problem was fixed.

Senghor answered 23/7, 2012 at 15:56 Comment(1)
When rename the file, the name of the class is not update on every sites, this is my case.Crudden
T
1

In my case error was thrown, because of missing namespace.

Tanh answered 31/1, 2022 at 10:22 Comment(1)
More specifically the 'designer' file doesn't always generate with the proper namespace. Updating it to have the right namespace fixes the issue.Edla

© 2022 - 2024 — McMap. All rights reserved.