为什么在消息框中未显示自定义的验证器的错误信息? [英] Why The error message for custom validator is not shown in message box?

查看:159
本文介绍了为什么在消息框中未显示自定义的验证器的错误信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了很多方式,但在验证摘要中未显示自定义验证错误信息,但它(的ValidationSummary)显示错误消息,为每个其他类型的验证的。

 <%@页面语言=C#AutoEventWireup =真codeFILE =Expt_Custom Validator.aspx.cs继承=Expt_Custom_Validator%GT;!< D​​OCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>
    <标题>无标题页< /标题>
    <脚本=服务器>
        保护无效CustomValidator1_ServerValidate(对象源,ServerValidateEventArgs参数)
        {
            如果(args.Value.Equals(Jagdeep))
                args.IsValid = FALSE;
            其他
                args.IsValid = TRUE;        }
    < / SCRIPT>
< /头>
<身体GT;
    <表ID =form1的=服务器>
    < D​​IV>
        < ASP:标签ID =lblName=服务器文本=输入您的姓名>< / ASP:标签>
        < ASP:文本框ID =txtbxName=服务器>< / ASP:文本框>        < ASP:的CustomValidator ID =CustomValidator1=服务器
            的ErrorMessage =你不准显示=无
            onservervalidate =CustomValidator1_ServerValidate>< / ASP:的CustomValidator>
        < BR />
        < ASP:标签ID =lblClass=服务器文本=类>< / ASP:标签>
        < ASP:文本框ID =txtClass=服务器>< / ASP:文本框>
        < ASP:的RequiredFieldValidator ID =RequiredFieldValidator1=服务器
            的ErrorMessage =请输入柯乐的ControlToValidate =txtClass显示=无>< / ASP:&的RequiredFieldValidator GT;
        < BR />        < ASP:的ValidationSummary ID =ValidationSummary1=服务器/>
        < BR />
        < ASP:按钮的ID =Button1的=服务器文本=验证/>    < / DIV>
    < /表及GT;
< /身体GT;
< / HTML>


解决方案

自定义验证,在FormView控件放置时不会显示服务器端验证后的错误消息(尽管它已经被验证,结果是无效的)平均修复这一个更新面板包裹。

I have tried in many way but the error message for custom validator is not shown in validation summary but it(ValidationSummary) shows error message for every other type of validator.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Expt_Custom Validator.aspx.cs" Inherits="Expt_Custom_Validator" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script runat="server">
        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.Value.Equals("Jagdeep"))
                args.IsValid = false;
            else
                args.IsValid = true;

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblName" runat="server" Text="Enter Your Name"></asp:Label>
        <asp:TextBox ID="txtbxName" runat="server"></asp:TextBox>

        <asp:CustomValidator ID="CustomValidator1" runat="server" 
            ErrorMessage="You are Not allowed" Display="None" 
            onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
        <br />
        <asp:Label ID="lblClass" runat="server" Text="Class"></asp:Label>
        <asp:TextBox ID="txtClass" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ErrorMessage="Please enter Clas" ControlToValidate="txtClass" Display="None"></asp:RequiredFieldValidator>
        <br />

        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Validate" />

    </div>
    </form>
</body>
</html>

解决方案

Custom Validator, when placing in formview will not show its error message after server-side validation (though it has been validated and result is invalid) the mean to fix this in to wrap it by a Update Panel.

这篇关于为什么在消息框中未显示自定义的验证器的错误信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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