Friday, July 7, 2017

How to add Multiple validation group to the same control ?



In some conditions we may need to validate a controls based on the different conditions consider the below example in which we are validating the same dropdown list from two different validation group Here we are using the  Page_ClientValidate('your validation group name') method which will accept the validation group name as input
  

Example:- 

 
<form id="form1" runat="server">
        <asp:Button Text="First" runat="server" ValidationGroup="firstVG" />
        <asp:Button Text="Second" runat="server" ValidationGroup="secondVG"  OnClientClick="return Check(); " />

        <asp:DropDownList runat="server" ValidationGroup="first" ID="ddl">
            <asp:ListItem Text="--Select--" Value="-1" />
            <asp:ListItem Text="A" />
            <asp:ListItem Text="B" />
        </asp:DropDownList>
        <asp:RequiredFieldValidator ErrorMessage="*" Display="Dynamic" ForeColor="Red" ControlToValidate="ddl" runat="server"  InitialValue="-1" ValidationGroup="firstVG"/>

    </form>

JavaScript File :- 

 

    <script type="text/javascript">
        function Check() {

            var isValid = false;
            isValid = Page_ClientValidate('secondVG');
            if (isValid) {
                isValid = Page_ClientValidate('firstVG');
            }

            return isValid;

        }
    </script>

No comments:

Post a Comment

Git Commands

Git Version   To check the git version Git -v       Git Clone To clone the repository, use the following command: Git clone [u...