问题描述
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).
我以前用相同的方式做了许多自定义控件,但是,此错误使我发疯.我在App_Code
目录中有一个带有以下类的Web应用程序项目,在web.config中有一个用于该类控件的tagprefix引用. 我现在该怎么办?
I had done many custom controls before the same way but Hell this error is driving me nuts. 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?
<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();
}
}
}
尝试了这些
-
http://support.microsoft.com/kb/919284
基类包含字段'ScriptManager1',但是其类型(System.Web.UI.ScriptManager)与控件的类型(System.Web.UI.ScriptManager)不兼容
推荐答案
也尝试指定程序集名称:
Try specifying the assembly name too:
<add tagPrefix="CControls" namespace="web.App_Code" assembly="web.App_Code" />
为了清楚起见,我会考虑为您的自定义控件创建一个专用的命名空间.也许像
web.App_Code.CustomControls
: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" />
这篇关于基类包括字段,但类型与控件类型不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!