简体   繁体   English

清除基于验证组的ASP必需字段验证器错误消息

[英]Clear ASP required field validator error messages based on validation group

In one aspx page, there are 8 textboxes and have corresponding ASP required field validators. 在一个aspx页中,有8个文本框,并具有相应的ASP必填字段验证器。 First four required field validators belong to one ValidationGroup and the rest belongs to another ValidationGroup. 前四个必填字段验证器属于一个ValidationGroup,其余的则属于另一个ValidationGroup。 There are two Submit and Clear buttons as well. 还有两个提交和清除按钮。 On Clicking the first clear button I am clearing the first four set of textboxes from JavaScript. 在单击第一个清除按钮时,我正在从JavaScript清除前四个文本框。

Along with that I want to clear the error messages of the required field validators belonging to "group1" ValidationGroup from JavaScript. 与此同时,我想从JavaScript清除属于“ group1” ValidationGroup的必填字段验证器的错误消息。

So how to clear the validation Error messages corresponding to one ValidationGroup? 那么,如何清除与一个ValidationGroup对应的验证错误消息?

As you didn't provided your code so i assumed the id of your submit button is Button1 and add class to each required field validator of group 1 (let class name reqgr1 ) .and also you have tried it using jquery, so posting my answer in jquery. 由于您没有提供代码,因此我假设您的提交按钮的ID为Button1 ,并将类添加到组1的每个必需字段验证器中(让类名reqgr1 )。您也已经使用jquery进行了尝试,因此发布了我的答案在jQuery中。 just like 就像

<asp:RequiredFieldValidator ID="Req1" runat="server" ErrorMessage="fitext" ControlToValidate="TextBox1" ValidationGroup="g1" class="reqgr1"></asp:RequiredFieldValidator>

$(document).ready(function () {
            $('#Button1').on('click', function () {              
                  $('.reqgr1').html('');
             });
        });

this will remove error message of those required field validator.as these rquired field validator are converted into span tag after rendering. 这将删除那些必需的字段验证器的错误消息。因为渲染后将这些必需的字段验证器转换为span标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM