How to validate against Multiple validation groups

asp.netvalidationvalidationgroup

I have two validation groups: parent and child

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?

Best Answer

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>