简体   繁体   English

ASP.NET-多个验证组的单个ValidationSummary-如何?

[英]ASP.NET - Single ValidationSummary for multiple validation groups - How to?

I have a Masterpage with a ValidationSummary. 我有一个带有ValidationSummary的母版页。

I need to use at least two different validation groups on a subpage since I have two actions (buttons). 我需要在一个子页面上至少使用两个不同的验证组,因为我有两个操作(按钮)。 I would like the validation messages to be shown in the validation summary on the master page. 我希望验证消息显示在母版页的验证摘要中。 This is not possible as far as I know since the ValidationSummary is only able to display validation summary messages from one validation group. 据我所知,这是不可能的,因为ValidationSummary仅能够显示来自一个验证组的验证摘要消息。

I'm wondering what would be the best way to achieve this. 我想知道什么是实现这一目标的最佳方法。

I thought of creating a custom Validation Summary which could accept a list of ValidationGroups to display messages from. 我想创建一个自定义的验证摘要,该摘要可以接受ValidationGroups的列表以显示消息。

Any good ideas how to do this ? 有什么好主意怎么做?

I actually solved this by accident one day. 实际上,有一天我偶然地解决了这个问题。 Do not put a ValidationGroup on your button, set CausesValidation to False and then register a OnClientClick() function that looks like this: 不要将ValidationGroup放在按钮上,将CausesValidation设置为False,然后注册如下所示的OnClientClick()函数:

<asp:Button runat="server" ID="btnRequest" Text="Save" OnClientClick="Validate2('ValidationGroup')" CausesValidation="False"/>

function Validate2(valgrp) {
    var isValid = false;
    isValid = Page_ClientValidate(valgrp);
    ValidatorUpdateIsValid();
    ValidationSummaryOnSubmit(null);
    return isValid;
}

You can call this multiple times Page_ClientValidate(valgrp); 您可以多次调用此方法Page_ClientValidate(valgrp); inside the javascript 在javascript中

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

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