ASP.NET 2.0 provide number of client side validation controls. One control is CompareValidator, which help to compare two values at client side without writing a javascript code. This example helps you to compare two string values without writing extra code.
Just assign ControlToValidate="txtName1" ControlToCompare="txtName2" the name of two textboxes need to compare and all is done.
CompareValidator in ASP.NET | How to Compaire Two String Values in ASP.NET Example:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<body>
<form id="Form1" runat="server">
<h4>
Compare two values</h4>
Value 1:
<asp:TextBox ID="txtName1" runat="server" />
<br />
<br />
Value 2:
<asp:TextBox ID="txtName2" runat="server" />
<br />
<br />
<br />
<asp:Button ID="Button1" Text="Validate" runat="server" />
<br />
<br />
<br />
<asp:CompareValidator ID="compair_values" Display="dynamic" ControlToValidate="txtName1" ControlToCompare="txtName2"
ForeColor="red" Type="String" Text="Validation Failed!"
runat="server" />
</form>
</body>
</html>
No comments:
Post a Comment