Validators
Validators
<asp:RequiredFieldValidator
ID=“ " runat="server"
ControlToValidate =“ "
ErrorMessage=“ “
InitialValue=“ ">
</asp:RequiredFieldValidator>
The RangeValidator control verifies that the
input value falls within a predetermined
range. It has three specific properties:
<asp:RangeValidator
ID=“ " runat="server"
ControlToValidate =“ "
ErrorMessage=“ “
Maximum=“ “ Mininum=“ “ Type=“”
</asp:RangeValidator>
The RegularExpressionValidator allows
validating the input text by matching against
a pattern of a regular expression. The regular
expression is set in the Validation Expression
property.
<asp:RegularExpressionValidator
ID=“ " runat="server"
ControlToValidate =“ "
ErrorMessage=“ “
ValidationExpression=“string">
</asp:RegularExpressionValidator>
The CompareValidator control compares a
value in one control with a fixed value or a
value in another control.
<asp:CompareValidator
ID=“ " runat="server"
ControlToCompare =“ control1 "
ValueToCompare=“control2 “
Operator=“ “
ErrorMessage=“ “
</asp:CompareValidator>
The ValidationSummary control does not perform any validation but
shows a summary of all errors in the page.
<asp:ValidationSummary
ID="ValidationSummary1“
runat="server"
DisplayMode = "BulletList/List/etc"
ShowSummary = "true/false“
HeaderText=“ " />
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Enter your name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Name is compulsory"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator><br />