c# - 无法让子类工作

标签 c# asp.net

我正在尝试创建 asp:DropDownList 的子类,以便我可以改用 asp:DdlNoEventValidation。这样我就可以绕过事件验证。

这是页面指令

<%@ Register TagPrefix="asp" Namespace="System.Web.UI.WebControls" Assembly="NoValidationDropDownList" %>

这是应该继承 DropDownList 的类(它是一个单独的 .cs 文件,位于 App_Code 中)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace System.Web.UI.WebControls
{
    public class DdlNoEventValidation : System.Web.UI.WebControls.DropDownList
    {
    }
}

这是我遇到的错误

Warning 1 Element 'DdlNoEventValidation' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.

Error 2 Could not load file or assembly 'NoValidationDropDownList' or one of its dependencies. The system cannot find the file specified.

Error 3 Unknown server tag 'asp:DdlNoEventValidation'.

这应该很简单,尽管在这里和互联网上的其他地方拖网寻找答案,但我显然做错了什么。这让我发疯,请帮忙!

最佳答案

不要在自定义代码中使用 System.Web.UI.WebControls 命名空间,就好像它是您自己的命名空间一样。

Microsoft 程序集中的控件是签名 - 你的不是(即使是,它们也不会有相同的签名,原因很明显)。

因此,使用此命名空间不是一个好主意 - 为您的控件使用您自己的自定义命名空间。

关于c# - 无法让子类工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9153120/

相关文章:

asp.net - 无法使用 ASP.NET AJAX 从 JSON 反序列化 Nullable KeyValuePair

c# - 使用对象绑定(bind)器在 C# 中映射 ajax 数据

asp.net - SignalR 调用服务器方法在 VS 中本地工作,但在 IIS 7.5 中不工作

c# - Asp.net Core rc2 web api文件上传

c# - 本应增加 1 的分数却增加了 2

C# 和 Delphi 集成

c# - 为什么同步上下文不适用于等待?

c# - 检查控制计时器的线程的状态

javascript - IE10 发送带小数(浮点值)的图像按钮单击坐标导致 ParseInt32 FormatException

c# - 将 Excel 范围转换为 ADO.NET 数据集或数据表等