如何在按钮单击时一次使用多个验证器? [英] How to use more than one validator at a time on button click ?

查看:80
本文介绍了如何在按钮单击时一次使用多个验证器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有2个文本框和3个下拉列表作为必填字段。我正在使用javascript和asp .net验证器进行验证。当我点击提交按钮时,所有5个验证器都应该有效。但在我的代码中只有一个验证器工作。
我的javascript代码是:
var Page_IsValid = false;
Page_IsValid = Page_ClientValidate('valgrpCode');
Page_IsValid = Page_ClientValidate('valgrpDescription');
Page_IsValid = Page_ClientValidate('valgrpCategory');
和我的asp代码是:
< asp:RequiredFieldValidator ID = reqCode runat = server ErrorMessage = * ControlToValidate = txtCode ValidationGroup = valgrpCode ForeColor = 红色 > ; < / asp:RequiredFieldValidator > ;
< asp:RequiredFieldValidator ID = reqDescription runat = server ErrorMessage = * ControlToValidate = txtDescription ValidationGroup = valgrpDescription ForeColor < span class =code-keyword> = 红色 > < / asp:RequiredFieldValidator >

< asp:RequiredFieldValidator ID = reqCategory < span class =code-attribute> runat = server ErrorMessage = * ControlToValidate = txtCategory ValidationGroup = valgrpCategory ForeColor = 红色 > < / asp:RequiredFieldValidator >

并且在这里我显示*作为强制性消息。但我需要将标签的颜色更改为强制性消息。我为每个文本框和下拉列表添加了标签。

解决方案

您好,



每个验证控件只需使用一个验证组。



 <   asp:requiredfieldvalidator     id   =  reqCode    runat   =  server    errormessage   =  *    controltovalidate   =  txtCode    validationgroup   =  valgrpCode    forecolor   =  红色    xmlns:asp   = #unknown >  <   / asp:requiredfieldvalidator  >  
< asp:requiredfieldvalidator id = reqDescription < span class =code-attribute> runat = server errormessage = * controltovalidate = txtDescription validationgroup = valgrpCode forecolor < span class =code-keyword> = 红色 xmlns:asp = #unknown > < / asp:requiredfieldvalidator >

< asp:requiredfieldvalidator id = reqCategory runat = server errormessage = * controltovalidate = txtCategory validationgroup = val grpCode forecolor = 红色 xmlns:asp = #unknown > < / asp:requiredfieldvalidator >


Hi,
     I have 2 text boxes and 3 drop down lists as mandatory fields. I am using javascript and asp .net validator for validation. When I click on the submit button all the 5 validator should work. But in my code only one validator is working.
My javascript code is:
var Page_IsValid = false;
Page_IsValid =Page_ClientValidate('valgrpCode');
Page_IsValid = Page_ClientValidate('valgrpDescription');
 Page_IsValid = Page_ClientValidate('valgrpCategory');
and my asp code is:
<asp:RequiredFieldValidator ID="reqCode" runat="server" ErrorMessage="*" ControlToValidate="txtCode" ValidationGroup="valgrpCode" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="reqDescription" runat="server" ErrorMessage="*" ControlToValidate="txtDescription" ValidationGroup="valgrpDescription" ForeColor="Red"></asp:RequiredFieldValidator>

<asp:RequiredFieldValidator ID="reqCategory" runat="server" ErrorMessage="*" ControlToValidate="txtCategory" ValidationGroup="valgrpCategory" ForeColor="Red"></asp:RequiredFieldValidator>

and also here i am showing "*" as mandatory message.  But I need to change the color of label as mandatory message. I have added labels for each text boxes and drop down lists.

解决方案

Hello,

You have to use only one validation group for each validation control.

<asp:requiredfieldvalidator id="reqCode" runat="server" errormessage="*" controltovalidate="txtCode" validationgroup="valgrpCode" forecolor="Red" xmlns:asp="#unknown"></asp:requiredfieldvalidator>
<asp:requiredfieldvalidator id="reqDescription" runat="server" errormessage="*" controltovalidate="txtDescription" validationgroup="valgrpCode" forecolor="Red" xmlns:asp="#unknown"></asp:requiredfieldvalidator>
 
<asp:requiredfieldvalidator id="reqCategory" runat="server" errormessage="*" controltovalidate="txtCategory" validationgroup="valgrpCode" forecolor="Red" xmlns:asp="#unknown"></asp:requiredfieldvalidator>


这篇关于如何在按钮单击时一次使用多个验证器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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