Base class includes field but type not compatible with type of control

38,431

Solution 1

Try specifying the assembly name too:

<add tagPrefix="CControls" namespace="web.App_Code" assembly="web.App_Code" />

I would consider creating a dedicated namespace for your custom controls, just for the sake of clarity. Maybe something like web.App_Code.CustomControls:

<add tagPrefix="CControls" namespace="web.App_Code.CustomControls" assembly="web.App_Code.CustomControls" />

Solution 2

Unckeck the build (and publish) option "Allow this precompiled site to be updatable"

It might not be enought for the runtime, so check the option "use fixed naming and single page assemblies" and it solved my case :)

here is a useful link about this error: http://forums.asp.net/t/960707.aspx

Solution 3

Refer the ascx user control in the web.conf instead of the aspx page like this:

<add tagPrefix="proj1" src="~/userControls/Invoiceshow.ascx" tagName="proj1tagname">

That solved my issue.

Solution 4

Encountered this problem while converting a Web Forms website to MVC Web App, and changing target framework to 4.6. The solution for me was to set the controlRenderingCompatibilityVersion attribute on the pages element in web.config:

<system.web>
   <pages validateRequest="true" controlRenderingCompatibilityVersion="4.6" clientIDMode="AutoID">
</system.web>

Solution 5

I know this is old, but I had the same error trying to change a textbox to a label control. I simply changed the ID of the control from "Insulin" to "Insulin2" which fixed the issue. I'm not sure why it worked, but that may be a question for Microsoft.

After looking into this more, I noticed if I closed the tab of the page I was working on in Visual Studio and then reopened it, the error went away all together? I hope this helps somebody.

Share:
38,431
Deeptechtons
Author by

Deeptechtons

SOreadytohelp Deeptechtons Programmer, Developer and Enthusiast always looking for chances to learn interesting technology. Meet awesome people and enhance life of people

Updated on February 08, 2022

Comments

  • Deeptechtons
    Deeptechtons over 2 years

    The base class includes the field 'lbl', but its type (web.App_Code.CustomLabelControl) is not compatible with the type of control (web.App_Code.CustomLabelControl).

    I had done many custom controls before the same way but today I ran into this error.

    I have a web application project with the below class in App_Code directory a tagprefix reference in web.config for the control in class.

    What do I do now?

    Web.Config

    <system.web>
        <pages>
            <controls>
                <add namespace="web.App_Code" tagPrefix="CControls"/>...
    

    Markup

    <form id="form1" runat="server">
    <div>
        <CControls:CustomLabelControl runat="server" OnClickText="Welcome" ID="lbl">
        </CControls:CustomLabelControl>
    </div>
    </form>
    

    Class File

    namespace web.App_Code
    {
        public class CustomLabelControl : Control, IPostBackEventHandler, IPostBackDataHandler
        {
            private string _onClickText;
    
            public CustomLabelControl()
            {
    
            }
    
            public string OnClickText
            {
                get { return _onClickText; }
                set { _onClickText = value; }
            }
    
            public void RaisePostBackEvent(string eventArgument)
            {
                throw new System.NotImplementedException();
            }
    
    
            public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
            {
                throw new System.NotImplementedException();
            }
    
    
            public void RaisePostDataChangedEvent()
            {
                throw new System.NotImplementedException();
            }
        }
    }
    

    I've checked these resources already:

  • Fábio Junqueira
    Fábio Junqueira over 7 years
    Just unchecking "Allow this precompiled site to be updatable" did it for me, thank you! You can enable this behavior in every build by going to Properties -> MSBuild and unchecking it there