<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidatorsExample2.aspx.cs" Inherits="Validators.ValidatorsExample2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Validators Example</title>
<style type="text/css">
#form1
{
z-index: 1;
left: 10px;
top: 130px;
position: absolute;
height: 19px;
width: 754px;
}
</style>
</head>
<body bgcolor="#ffff99">
<h3>This example
demonstrates the use of Validator controls with a ValidationSummary
control to
validate a form's controls.</h3>
<ul>
<li>Employee Name Textbox uses a RequiredFieldValidator
control.</li>
<li>Hourly Rate Textbox
uses a CompareValidator control and a RequiredFieldValidator
control.</li>
<li>Security Level Textbox uses a RangeValidator
control and a
RequiredFieldValidator
control.</li>
<li>The error messages are displayed in a ValidationSummary
control.</li>
</ul>
<form id="form1" runat="server">
<asp:Label ID="lblMessage" runat="server" Font-Bold="True"
style="z-index: 1; left: 10px; top: 54px; position: absolute" />
<asp:TextBox ID="txtName" runat="server" Height="19px" Width="180px"
style="z-index: 1; left: 154px; top: 87px; position: absolute"></asp:TextBox>
<asp:RequiredFieldValidator ID="valName" runat="server"
ControlToValidate="txtName" ErrorMessage="Employee Name is required" Font-Bold="False"
ForeColor="#CC0000"
style="z-index: 1; left: 342px; top: 86px; position: absolute; height: 19px">*</asp:RequiredFieldValidator>
<asp:TextBox ID="txtRate" runat="server" Height="19px" Width="70px"
style="z-index: 1; left: 153px; top: 124px; position: absolute; bottom: 349px"></asp:TextBox>
<asp:CompareValidator ID="valRate" runat="server" ControlToValidate="txtRate"
ErrorMessage="Enter
a numerical value under 100 for Hourly Rate" ForeColor="#CC0000"
Operator="LessThanEqual"
style="z-index: 1; left: 235px; top: 124px; position: absolute" Type="Currency"
ValueToCompare="100">*</asp:CompareValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Hourly
Rate is required." ForeColor="#CC0000"
style="z-index: 1; left: 250px; top: 124px; position: absolute"
ControlToValidate="txtRate">*</asp:RequiredFieldValidator>
<asp:TextBox ID="txtSecurityLevel" runat="server" Height="19px" Width="70px"
style="z-index: 1; left: 151px; top: 161px; position: absolute"></asp:TextBox>
<asp:RangeValidator ID="valSecurityLevel" runat="server"
ControlToValidate="txtSecurityLevel"
ErrorMessage="Invalid Security Level (value must be 0 - 5)" ForeColor="#CC0000"
MaximumValue="5" MinimumValue="0"
style="z-index: 1; left: 233px; top: 161px; position: absolute">*</asp:RangeValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtSecurityLevel" ErrorMessage="Security Level is required"
ForeColor="#CC0000"
style="z-index: 1; left: 249px; top: 161px; position: absolute">*</asp:RequiredFieldValidator>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" Height="25px"
Width="75px"
style="z-index: 1; left: 148px; top: 210px; position: absolute" OnClick="btnSubmit_Click" />
<asp:ValidationSummary ID="valErrorList" runat="server" ForeColor="#CC0000"
style="z-index: 1; left: 126px; top: 251px; position: absolute; height: 38px; width: 477px" />
<asp:Label ID="Label1" runat="server"
style="z-index: 1; left: 38px; top: 86px; position: absolute"
Text="Employee Name:"></asp:Label>
<asp:Label ID="Label2" runat="server"
style="z-index: 1; left: 62px; top: 123px; position: absolute"
Text="Hourly Rate: "></asp:Label>
<asp:Label ID="Label3" runat="server"
style="z-index: 1; left: 49px; top: 158px; position: absolute; right: 613px; height: 22px;"
Text="Security Level:"></asp:Label>
</form>
</body>
</html>