| | | | | | | | | |
|
|
|
|
|
|
|
|
| |
1. ASP.NET CompareValidator Control
« Previous Chapter
Next Chapter » |
|
|
| |
The ASP.NET CompareValidator Control can be used to compare a value input to another input value or a fixed value.
Note:
- The ASP.NET CompareValidator Control will show successful comparison if the input was empty.
- Always use the ASP.NET RequiredFieldValidator control to make sure the Input control field is a required field.
The following is an ASP.NET tutorial how to add an ASP.NET CompareValidator Control in Visual Studio.
- Go to the Toolbox and under the Validation section, select CompareValidator.

ASP.NET CompareValidator Control
- Drag and drop it on to the Form area.
- The following is the code you get in the Source View.
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"></asp:CompareValidator>
- The following is shows an example use of the ASP.NET CompareValidator Control.
<form id="form1" runat="server">
<div>
<p>Comparing Values</p>
<asp:TextBox id="TextBox1" runat="server" />
<span>=</span>
<asp:TextBox id="TextBox2" runat="server" />
<asp:Button ID="Button2" Text="Validate" runat="server" />
<br />
<asp:CompareValidator id="CompareValidator1" Display="dynamic" ControlToValidate="TextBox1" ControlToCompare="TextBox2" ForeColor="red" BackColor="white" Type="String" EnableClientScript="false" Text="Comparision Failed" runat="server" />
</div>
</form>
Note:
- Two textbox controls and a button control named Validate was created.
- One CompareValidator control was created
- If the validation fails, the validation text “Comparison Failed” will be displayed in Red by the CompareValidator Control.
In the next chapter you will learn some of the properties of the ASP.NET CompareValidator Control.
« Previous Chapter
Next Chapter »
Table of Contents
» Chapter 1 - ASP.NET CompareValidator Control
Chapter 1.1 - ASP.NET CompareValidator Control Properties
Chapter 2 - ASP.NET CustomValidator Control
Chapter 2.1 - ASP.NET CustomValidator Control Properties
Chapter 3 - ASP.NET RangeValidator Control
Chapter 3.1 - ASP.NET RangeValidator Control Properties
Chapter 4 - ASP.NET RegularExpressionValidator Control
Chapter 4.1 - ASP.NET RegularExpressionValidator Control Properties
Chapter 5 - ASP.NET RequiredFieldValidator Control
Chapter 5.1 - ASP.NET RequiredFieldValidator Control Properties
Chapter 6 - ASP.NET ValidationSummary Control
Chapter 6.1 - ASP.NET ValidationSummary Control Properties
[top] |
|
| |
|
|
| | |
|
|
|