Dee*_*ons 13 c# asp.net postback app-code web-controls
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中的tagprefix引用,用于类中的控件.现在我该怎么做?
<system.web>
<pages>
<controls>
<add namespace="web.App_Code" tagPrefix="CControls"/>...
Run Code Online (Sandbox Code Playgroud)
<form id="form1" runat="server">
<div>
<CControls:CustomLabelControl runat="server" OnClickText="Welcome" ID="lbl">
</CControls:CustomLabelControl>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
也尝试指定程序集名称:
<add tagPrefix="CControls" namespace="web.App_Code" assembly="web.App_Code" />
Run Code Online (Sandbox Code Playgroud)
为了清楚起见,我会考虑为您的自定义控件创建一个专用的命名空间。也许像web.App_Code.CustomControls:
<add tagPrefix="CControls" namespace="web.App_Code.CustomControls" assembly="web.App_Code.CustomControls" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32335 次 |
| 最近记录: |