<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidatorsExample1.aspx.cs" Inherits="Validators.ValidatorsExample1" %>
<!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 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.</li>
<li>Security Level Textbox uses a RangeValidator
control.</li>
</ul>
<h3>
You must add the following code to the Web.config file for any project that contains validation
controls.
The code should appear in between the
configuration XML tags.
<pre>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode"
value="None" />
<appSettings />
</pre>
</h3>
<form id="form1" runat="server">
<asp:Label ID="lblMessage" runat="server" Font-Bold="True"
style="z-index: 1; left: 10px; top: 129px; position: absolute" />
<asp:TextBox ID="txtName" runat="server" Height="19px" Width="180px"
style="z-index: 1; left: 153px; top: 162px; position: absolute; right: 421px;"></asp:TextBox>
<asp:RequiredFieldValidator ID="valName" runat="server"
ControlToValidate="txtName" ErrorMessage="* Required" Font-Bold="False"
ForeColor="#CC0000"
style="z-index: 1; left: 342px; top: 162px; position: absolute; height: 19px"></asp:RequiredFieldValidator>
<asp:TextBox ID="txtRate" runat="server" Height="19px" Width="70px"
style="z-index: 1; left: 153px; top: 199px; position: absolute; bottom: 349px"></asp:TextBox>
<asp:CompareValidator ID="valRate" runat="server" ControlToValidate="txtRate"
ErrorMessage="* Enter a
numerical value under 100" ForeColor="#CC0000"
Operator="LessThanEqual"
style="z-index: 1; left: 235px; top: 199px; position: absolute" Type="Currency"
ValueToCompare="100"></asp:CompareValidator>
<asp:TextBox ID="txtSecurityLevel" runat="server" Height="19px" Width="70px"
style="z-index: 1; left: 151px; top: 236px; position: absolute"></asp:TextBox>
<asp:RangeValidator ID="valSecurityLevel" runat="server"
ControlToValidate="txtSecurityLevel"
ErrorMessage="* Invalid
Level (value must be 0
- 5)" ForeColor="#CC0000"
MaximumValue="5" MinimumValue="0"
style="z-index: 1; left: 233px; top: 236px; position: absolute"></asp:RangeValidator>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" Height="25px"
Width="75px"
style="z-index: 1; left: 148px; top: 285px; position: absolute" OnClick="btnSubmit_Click" />
<asp:Label ID="Label1" runat="server"
style="z-index: 1; left: 38px; top: 162px; position: absolute"
Text="Employee Name:"></asp:Label>
<asp:Label ID="Label2" runat="server"
style="z-index: 1; left: 62px; top: 199px; position: absolute"
Text="Hourly Rate: "></asp:Label>
<asp:Label ID="Label3" runat="server"
style="z-index: 1; left: 49px; top: 236px; position: absolute; right: 613px; height: 22px;"
Text="Security Level:"></asp:Label>
</form>
</body>
</html>