Web Tutorials

Interview Q & A

Code Examples

Utility Tools

ASP.NET Disabled Client Side CompareValidator

ASP.NET how to disable client side CompareValidator. The CompareValidator control belongs to System.Web.UI.WebControls

Syntax

<asp:CompareValidator ID="CompareValidator1" runat="server" Type="Integer"
 Operator="DataTypeCheck" ControlToValidate="txtNumber1" EnableClientScript="false"   
    ErrorMessage="Enter Number"></asp:CompareValidator>

ASP.NET CompareValidator Control Property

PropertyDescription
ControlToValidateSpecifies control name which needs to be validate.
DisplaySpecifies behavior of the error message.
EnableClientScriptSpecifies whether or not client-side validation is enabled.
EnabledSpecifies whether or not validation control is enabled or not.
ErrorMessageSpecifies error messageto be display in validation summary.
ForeColorSpecifies error message color.
IsValidIndicate if associate control passes validation or not.
SetFocusOnErrorSet focus on associate control if validation fails.
TextSpecifies text to be display if validation fails.
ValidationGroupSpecifies validation group name.
ValidateUpdate the isvalid propery.
ValidateGetValidationPropertyDetermineing validation property of a control, if it exists.
EqualThis is used to check whether the compared value are equal.
NotEqualThis is used to check whether the compared value are not equal.
GreaterThanThis is used to check whether the compared value are greater than.
GreaterThanEqualThis is used to check whether the compared value are greater than equal
LessThanThis is used to check whether the compared value are less than.
LessThanEqualThis is used to check whether the compared value are less than equal.
DataTypeCheckThis is used to compare data type.

ASP.NET Disabled Client Side CompareValidator Example Default.aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">  
    <title>ASP.NET CompareValidator Disabled Client Validation Example</title>  

</head>  
<body>  
<form id="Form" runat="server">  
<div> 
<asp:Label ID="lblTitle" runat="server" Font-Bold="True" Font-Size="Medium"   
    Font-Underline="True" Text="ASP.NET CompareValidator Disabled Client Validation Example"></asp:Label>  
<table border="0" cellpadding="4" cellspacing="4" width="420px;">
<tr><td><asp:Label ID="lblNumber1" runat="server" Font-Bold="True" Font-Size="Small"   
    Text="Enter Number:"></asp:Label></td>
    <td><asp:TextBox ID="txtNumber1" runat="server" Width="173px"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" Type="Integer"
 Operator="DataTypeCheck" ControlToValidate="txtNumber1" EnableClientScript="false"   
    ErrorMessage="Enter Number"></asp:CompareValidator> </td></tr>
<tr><td> </td><td><asp:Label ID="lblInterest" runat="server" Font-Bold="True" Font-Size="Small"   
    Text=""></asp:Label></td></tr>
<tr><td> </td><td> <asp:Button ID="btnSubmit" runat="server" Font-Bold="True"   
    Font-Size="Small" Text="Submit" onclick="btnSubmit_Click" /> </td></tr>
</table> 
</div>  
</form>   
</body>  
</html> 

ASP.NET Disabled Client Side CompareValidator Example Default.aspx.cs

protected void btnSubmit_Click(object sender, EventArgs e)
{
	if (IsValid)
	{
		int amount = Convert.ToInt32(this.txtNumber1.Text);
		int interest = 9;
		int totalInterest = amount * interest/100;
		lblInterest.Text = "Total Interest - " + totalInterest;
	}   
}

Above example will produce following output

RequiredFieldValidator

RegularExpressionValidator

RangValidator

CompareValidator

CustomValidator

ValidationSummary