Вы находитесь на странице: 1из 4

Summary Validation Example

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidationSummery.aspx.cs"


Inherits="WebApplication1.ValidationSummery" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 697px;
}

.auto-style2 {
width: 123px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="border: 1px solid gray; width: 400px">
<table border="0" class="auto-style1">
<tr>
<td colspan="2">
<h3 style="text-align:
left;">Registration Form</h3>
</td>
</tr>
<tr>
<td class="auto-style2">
<b>Email</b>
</td>
<td>
<asp:TextBox ID="txtEmail"
runat="server" Width="150px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Email Filed Is
Required!"
ControlToValidate="txtEmail"
ForeColor="Red"
Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Invalid Email!"
ForeColor="Red"
ControlToValidate="txtEmail"
ValidationExpression="\w+([-
+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Display="Dynamic">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<b>UserName</b>
</td>
<td>
<asp:TextBox ID="txtUserName"
runat="server" Width="150px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ErrorMessage="User Name Filed Is
Required!"
ControlToValidate="txtUserName"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<b>Password</b>
</td>
<td>
<asp:TextBox ID="txtPassword"
runat="server" Width="150px"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3" runat="server"
ErrorMessage="Password Filed Is
Required!"
ControlToValidate="txtPassword"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<b>Retype Password</b>
</td>
<td>
<asp:TextBox ID="txtRetypePassword"
runat="server" Width="150px"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator4" runat="server"
ErrorMessage="Retype Password
Filed Is Required!"

ControlToValidate="txtRetypePassword" ForeColor="Red"
Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:CompareValidator
ID="CompareValidator1" runat="server"
ErrorMessage="Password and
Confrim Password Does Not Match!" ForeColor="Red"

ControlToValidate="txtRetypePassword"
ControlToCompare="txtPassword"
Type="String" Operator="Equal"
Display="Dynamic">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSave"
runat="server" Text="Save" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary
ID="ValidationSummary1" runat="server" ForeColor="Red"
HeaderText="Validation Errors" ShowMessageBox="True" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus"
runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>