Posted by : Anwar Hossain
Category : How to use different types of validation control using asp.net c#

How to use compare validation control using asp.net c#

Dear viewers I will show how to useasp.net client side validation control .Here compare validation control using has been implemented for comparison two values. We can say all modern browser sis capable to perform client side validation of a webpage. The common properties are:

ControlToValidate : it’s id can be specified for the target control to validate.

ControlToCompare : it’s id can be specified for the target control to compare.

Type : it’s id can be specified for data type verification.

Operator: It defines the type of comparison.

Compare Validators Example ASP.NET C#

 

HTML

html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <style type="text/css">
  .style1
  {
  width: 100%;
  }
  .style2
  {
  color: #FF9900;
  }
  .style3
  {
  color: Teal;
  }
  </style>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <span class="style3">
  <b style="font-weight: bold; font-size: x-large"> Password comparasion example</b></span>
 
  <table class="style1">
  <tr>
  <td width="150">
  &nbsp;
  </td>
  <td width="5px">
  &nbsp;
  </td>
  <td class="style2">
  </td>
  </tr>
  <tr>
  <td width="150">
  Enter your password
  </td>
  <td width="5px">
  :
  </td>
  <td>
  <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
  </td>
  </tr>
  <tr>
  <td>
  Retype your passoword
  </td>
  <td>
   &nbsp;:&nbsp;
  </td>
  <td>
  <asp:TextBox ID="TxtConfirmPassword" runat="server"></asp:TextBox>
  <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TxtConfirmPassword"
  ControlToValidate="txtPassword" ErrorMessage="Password must be same" ForeColor="#FF3300"></asp:CompareValidator>
  </td>
  </tr>
  </table>
 
  <span class="style3">
 
  <b style="font-weight: bold; font-size: x-large"> Less or greater than comparasion example</b></span>
 
  <table class="style1">
  <tr>
  <td width="150">
  Small Number
  </td>
  <td width="5px">
  :
  </td>
  <td>
  <asp:TextBox ID="txtSmallNumber" runat="server"></asp:TextBox>
  </td>
  </tr>
  <tr>
   <td>
  Big Number
  </td>
  <td>
  &nbsp;:&nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtBigNumber" runat="server"></asp:TextBox>
  <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToCompare="txtSmallNumber"
  ControlToValidate="txtBigNumber" ErrorMessage="Number Must be greater than"
  ForeColor="#FF3300" Operator="GreaterThan" Type="Integer"></asp:CompareValidator>
  </td>
  </tr>
  </table>
 
 
  <span class="style3"> <b style="font-weight: bold; font-size: x-large">  Not Equal example using compare validator </b></span>
 
  <table class="style1">
  <tr>
  <td width="150">
  First Number
  </td>
  <td width="5px">
  :
  </td>
  <td>
   <asp:TextBox ID="txtFirstNumber" runat="server"></asp:TextBox>
  </td>
  </tr>
  <tr>
  <td>
  Second Number
  </td>
  <td>
  &nbsp;:&nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtSecondNumber" runat="server"></asp:TextBox>
  <asp:CompareValidator ID="CompareValidator3" runat="server" ControlToCompare="txtFirstNumber"
  ControlToValidate="txtSecondNumber" ErrorMessage="Number is not allowed to equal"
  ForeColor="#FF3300" Operator="NotEqual" Type="Integer"></asp:CompareValidator>
  </td>
  </tr>
  </table>
  </div>
  </form>
</body>
</html>

Out Put

compareValidation_asp.net



Realted Article Headline

How to use RequiredFieldValidator for RadioButtonList in ASP.NET C#
How to use RequiredFieldValidator for DropDownList in ASP.NET C#
How to use RangeValidator in ASP.NET C#
how to use RequiredFieldValidator in ASP.NET C#
How to use RegularExpressionValidator Control in ASP.NET using C#
How to use Custom Validator control using asp.net c#
How to use compare validation control using asp.net c#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection