The ValidationSummary control does not perform specific validation but provides a list of errors in the page. The summary displays the values of the ErrorMessage property of all validation controls.
The following two mutually inclusive properties list out the error message:
ShowSummary: shows the error messages in the specified format.
ShowMessageBox: shows the error messages in a separate window.
The syntax for the control is as given:
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
DisplayMode="BulletList" ShowSummary="true"/ShowMessageBox="true" HeaderText="Errors:" />
ShowSummary Example
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RequiredFieldvalidator.aspx.cs" Inherits="WebProgramming.Validators.RequiredFieldvalidator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>UserName:
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="UserName is required." Text="*" ControlToValidate="txtUserName"></asp:RequiredFieldValidator></td>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Username should have atleast a capital letter" ControlToValidate="txtUserName" OnServerValidate="CustomValidator1_ServerValidate" SetFocusOnError="True"></asp:CustomValidator>
</tr>
<tr>
<td>Password:
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Password is required." Text="*" ControlToValidate="txtPassword"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Confirm password:
<asp:TextBox ID="txtConfirmvalidator" runat="server" TextMode="Password"></asp:TextBox><asp:RequiredFieldValidator ID="RangeValidator2" runat="server" Text="*" ErrorMessage="Confirm password is required." ControlToValidate="txtConfirmvalidator" MinimumValue="18" MaximumValue="35"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvConfirmpassword" runat="server" ControlToValidate="txtConfirmvalidator" ControlToCompare="txtPassword" ErrorMessage="Password mismatch"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>Age:
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Age is required." Text="*" ControlToValidate="txtAge"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="rfvAge" Text="*" runat="server" ErrorMessage="User age should be with in 18-35." ControlToValidate="txtAge" MinimumValue="18" MaximumValue="35"></asp:RangeValidator></td>
</tr>
<tr>
<td>Email:
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Email is required." Text="*" ControlToValidate="txtEmail"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RangeValidator1" runat="server" ErrorMessage="Supplied email is not in correct format." Text="*" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
DisplayMode="BulletList" ShowSummary="true" HeaderText="Errors:" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
In the attributes ShowSummary="true", then the out displays in the general text format.
if ShowMessageBox="true" is true, the out put is a popup message.
Output




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery
No comments:
Post a Comment