ASP.NET Basics

HTML Basics
ASP.NET Web Server
Advanced HTML
Application Designing
Using Visual Studio
ASP.NET Standards
ASP.NET Styling
ASP.NET Navigation

ASP.NET Tips

ASP.NET Validation
HTML forms
CSS Styling
CSS Advanced
ASP.NET Features
ASP.NET Image Effects
Common mistakes
DB Design tips

Building Applications

Design Secure Apps
Build Secure Apps

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.

  1. Go to the Toolbox and under the Validation section, select CompareValidator.

ASP.NET CompareValidator Control
ASP.NET CompareValidator Control

  1. Drag and drop it on to the Form area.

  2. The following is the code you get in the Source View.

<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"></asp:CompareValidator>

  1. 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]