C# 自定义验证错误

C# 自定义验证错误,c#,asp.net,.net,C#,Asp.net,.net,我的用户控件类似于: <asp:TextBox ID="_txtLeadDate" runat="server" ReadOnly="true"> </asp:TextBox> <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="_txtLeadDate" ErrorMessage="You cannot select a day earli

我的用户控件类似于:

    <asp:TextBox ID="_txtLeadDate" runat="server" ReadOnly="true">
    </asp:TextBox>
    <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="_txtLeadDate" ErrorMessage="You cannot select a day earlier than today!" OnServerValidate="CustomValidator2_ServerValidate" SetFocusOnError="True">&nbsp;
    </asp:CustomValidator>
但页面显示错误:

“ASP.usercontrol\u preordercontrol\u ascx”不包含“CustomValidator2\u ServerValidate”的定义,并且找不到接受“ASP.usercontrol\u preordercontrol\u ascx”类型的第一个参数的扩展方法“CustomValidator2\u ServerValidate”(是否缺少using指令或程序集引用?)


确保以下事件

protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)

在UserControl(.ascx)的代码隐藏中声明,而不是在调用此UserControl的.aspx表单中声明。

这些控件是
UserControl
的一部分?@RahulSingh Yes。这些都在用户控件中。但是,您已经编写了我的
asp
页面了吗?这很混乱,应该是用户控制页,对吗?Alos,您已经在用户控件的代码隐藏中添加了此自定义验证程序代码?是的。一切都由用户控制。我不喜欢提到asp页面。将编辑it@MahatmaAladdin,我建议从ascx中删除事件并进行代码隐藏,然后通过ascx再次重新生成它们,看看这是否有帮助!又是一次毫无理由的负面评论。虽然这是一篇老文章,但我仍然记得这是一个正确的观点。usercontrol事件的代码隐藏应该在用户控件的代码隐藏中声明,而不是在aspx页面的代码隐藏中声明。
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)