Saturday 22 March 2014

compare validator in asp.net

Compare ValidatorCheck that the value in the validated control has specific defined range. user's input is in a given range(Number or Character).  
Event will fire or control will validate only once user click on Button.
Important Property which need to handle for compare Validator is;

ControlToValidate – Linked with id which control to validate;
EnableClientScript - specifies client-side validation is enabled or not (true/false)
Display – Contain three value None- the control is not displayed; Static - Control displays an error message if it’s not validate. Space is kept on the page for the message; Dynamic - Control displays an error message if it’s not validate. Space is not kept on the page for the message;
Enabled - specifies whether the validation control is enabled or not(true/false)
ErrorMessage - text to display in the ValidationSummary control when validation fails, it display in validation control also
ForeColor – Text color of message
Text - message to display when validation fails
ValidationGroup – Grouping all the validation control together
Operator - The type of comparison to perform. The operators are: ·      Equal ·      GreaterThan ·      GreaterThanEqual ·      LessThan ·      LessThanEqual ·      NotEqual ·      DataTypeCheck
Type - Specifies the data type of the values to compare. The types are:
  • Currency
  • Date
  • Double
  • Integer
  • String
ValueToCompare - specified value to compare with

@Code Snippet – Html code     Comapre validator
   <body>
    <form id="form1" runat="server">
    <div>
        <table border="0" bgcolor="#cccccc">
            <tr style="vertical-align: top">
                <td colspan="4">
                    <h4>
                        Compare two values - Password</h4>
                </td>
            </tr>
            <tr><td>
            <asp:CompareValidator ID="compval" Display="dynamic" ControlToValidate="txtPassowrd" ControlToCompare="txtComparepassword"
            ForeColor="red" BackColor="yellow" Type="String" EnableClientScript="false" Text="Password Validation  Failed!"
            runat="server" />
            </td>
            </tr>
            <tr style="vertical-align: top">
                <td>
                  Password :  <asp:TextBox ID="txtPassowrd" runat="server" />
                </td>
                <td>
                  Validate Password :  <asp:TextBox ID="txtComparepassword" runat="server" />
                </td>
                <td>
                    <asp:Button ID="Button1" Text="Validate" runat="server" />
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
 In above code validating compare Password

@OutPut screen
Once user not enter any value in text box and click on Button;

No comments:

Post a Comment