gpt4 book ai didi

c# - 基类包含字段但类型与控件类型不兼容

转载 作者:可可西里 更新时间:2023-11-01 08:10:24 26 4
gpt4 key购买 nike

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).

我以前用同样的方法做过很多自定义控件,但今天我遇到了这个错误。

我有一个 Web 应用程序项目,在 App_Code 目录中有以下类,在 web.config 中为类中的控件引用了一个标签前缀。

我现在该怎么办?

Web.Config

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

标记

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

类文件

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

我已经检查了这些资源:

最佳答案

也尝试指定程序集名称:

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

为了清楚起见,我会考虑为您的自定义控件创建一个专用的命名空间。可能类似于 web.App_Code.CustomControls:

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

关于c# - 基类包含字段但类型与控件类型不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8230599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com