我正在尝试创建 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/