是否可以为自定义验证器显示多个错误消息? [英] Is it possible to display more than one error message for custom validator?

查看:62
本文介绍了是否可以为自定义验证器显示多个错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能知道自定义验证器可能会显示多个错误消息,如果显示怎么办?我想显示错误消息的原因有两个:1.如果txtbox为空,2.如果单词与数据库中的单词不匹配.
帮助我..

can anyone know that it possible to display more than one error message for custom validator.if so how to display? I want to display error message for 2 reason, 1.if txtbox is empty and 2.if words mismatch with the one in database.
help me pls..

推荐答案

所以您不能在服务器端进行验证吗?因为您正在从数据库进行验证,所以您必须从服务器端进行验证.


so are you not able to validate on Server side? Because you are validating from DB so you have to validate from server side.


<asp:CustomValidator runat="server" id="cusCustom" controltovalidate="txtCustom" onservervalidate="cusCustom_ServerValidate" errormessage="Error message!" />

protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e)
{
    if(//validatation is true)
        e.IsValid = true;
    else
        e.IsValid = false;
}


通常,每个文本框只写一条消息.

因此,如果文本框为空,则将编写类似此字段为必填项"的内容,并且无需费心检查该单词是否与数据库中的单词匹配...

如果文本框不为空,则将进行下一个验证.
Generally, you would write only one message per textbox.

Thus if the text box is empty, you will write something like "this field is required" and you won''t bother checking if the word matches a word in the database or not...

If the textbox is not empty, then you will do the next validation.


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

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