自定义验证错误 [英] Custom Validation error

查看:85
本文介绍了自定义验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户控制NAme: PreOrderControl.ascx

代码背后: PreOrderControl.ascx.cs



我的用户控制如下:



User Control NAme: PreOrderControl.ascx
Code Behind: PreOrderControl.ascx.cs

My user control is like:

<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>







和服务器端代码是:






and the server side code is:

protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
    {



        if (some condition)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }


    }





但页面显示错误:



'ASP.usercontrol_preordercontrol_ascx'不包含'CustomValidator2_ServerValidate'的定义,并且没有可以找到接受ASP.usercontrol_preordercontrol_ascx类型的第一个参数的扩展方法'CustomValidator2_ServerValidate'(你错过了使用指令或汇编引用吗?)





请帮忙。



But the page is showing error:

'ASP.usercontrol_preordercontrol_ascx' does not contain a definition for 'CustomValidator2_ServerValidate' and no extension method 'CustomValidator2_ServerValidate' accepting a first argument of type 'ASP.usercontrol_preordercontrol_ascx' could be found (are you missing a using directive or an assembly reference?)


Kindly help.

推荐答案

您可能已重命名用户控件但未相应更新ascx文件引用。例如

you may have renamed your user control but haven't updated ascx file references accordingly. for example
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PreOrderControl.ascx.cs" Inherits="MyApp.PreOrderControl" %>



和你的PreOrderControl.ascx.cs文件如下所示,


and your PreOrderControl.ascx.cs file would be like below,

namespace MyApp
{
    public partial class PreOrderControl : System.Web.UI.UserControl
    {



请注意ascx文件中的 CodeBehind 继承属性,它们应与文件名和带有命名空间的类名匹配


note the CodeBehind in ascx file and the Inherits properties, they should match with the file name and the class name with your namespace


这篇关于自定义验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆