VB.net Tutorials with Examples

VB.Net Projects

VB.Net Project 1

adplus-dvertising
CompareValidator control
Previous Home Next

This Control is used to compare the value or one control to the value of another control or to a fixed value. One catch here is that validation pass if both the fields are empty. To handle that one require to apply Required field validator along with CompareValidator.

Example

<asp:TextBox ID="TextBox1" runat="server" />
<asp:TextBox ID="TextBox2" runat="server" />
<asp:CompareValidator ID="CompareValidator1"
runat="server" ControlToValidate="TextBox2" 
Display="Dynamic" ValidationGroup="MyGroup" 
ToolTip=" password not matched No Match" 
ControlToCompare="TextBox1" >
* password not matche pls reenter password
</asp:CompareValidator>

ControlToCompare

This take the Id of control with which comparison is being done. Comparison can be made on following data types: Currency, Date, Double, Integer and String.

Properties

Properties Discription
ControlToCompare Specifies the name of the control which acts like a source control
Type Specifies the data type to be used for validating the input. Default type is ‘string’.
Operator Specifies the operator to be used for validating the user input. Default is ‘Equal’.
Grouping the validation controls together

In order to group the validation controls together ‘ValidationGroup’ property for all the controls which belongs to the group should be set with the same name.

Output:

if password are same

Otherwise

Previous Home Next