Categories
Asp, Asp.net

Compare Validator Example In Asp.Net

Compare Validator Example In Asp.Net

In this post we will learn how to use a Compare Validator in Asp.net,Compare Validator Example In Asp.Net.Compare Validator can compare two values, for instance the values of two controls.With Compare Validator, Controltovalidate attribute to specify which control to validate.In addition to that, we specify a control to compare.The operator attribute specifies which method to use when comparing.

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Compare Validator In Asp.Net, Compare Validator Example In Asp.Net</title>
<style>
body
{
margin:0px auto;
width:800px;
font-family:Calibri;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Compare Validator In Asp.Net, Compare Validator Example In Asp.Net</h2>    
<br /><br /><br /><br />
First Number: <asp:TextBox ID="frstn" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Second Number: <asp:TextBox ID="scndn" runat="server"></asp:TextBox><br /><br />
<asp:CompareValidator ID="CV1" runat="server" ControlToValidate="frstn" ControlToCompare="scndn" Operator="Equal" Type="Integer" ErrorMessage="First & Second Number Should Be Same"></asp:CompareValidator>
</div>
</form>
</body>
</html>

One reply on “Compare Validator Example In Asp.Net”

Comments are closed.