如何验证对多重验证组? [英] How to validate against Multiple validation groups?

查看:196
本文介绍了如何验证对多重验证组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个验证组:家长和孩子

I have two validation groups: parent and child

我有一个添加按钮,需要验证仅这是很容易做到的孩子验证组。保存按钮需要验证对家长和孩子验证组,客户端端和服务器端。我想我知道如何通过调用每个组的Page.Validate(组名)方法来做到这一点的服务器端,但它如何可以做到客户端?

I have an add button that needs to only validate the child validation group which is easily done. The save button needs to validate against the parent and child validation groups, both client side and server side. I think I know how to do it server side by calling the Page.Validate("groupname") method for each group, but how can it be done client side?

推荐答案

您应该能够创建一个使用的 Page_ClientValidate ,然后有按钮调用该函数

You should be able to accomplish this by creating a javascript function that uses Page_ClientValidate and then having the button call that function

<asp:Button ID="btnSave" Text="Save" OnClientClick="return validate()" runat="server" />

<script type="text/javascript">
    function validate() {
        var t1 = Page_ClientValidate("parent");
        var t2 = Page_ClientValidate("child");

        if (!t1 || !t2) return false;

        return true;
    }
</script>

这篇关于如何验证对多重验证组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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