Web Tutorials

Interview Q & A

Code Examples

Utility Tools

ASP.NET ValidationSummary Grouping

ASP.NET ValidationSummary is useful when you want to display error message in a group rather than individual error message for each control. The ValidationSummary control belongs to System.Web.UI.WebControls

Syntax

<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="BulletList" 
HeaderText="Error: " ShowMessageBox="true" ShowSummary="false" /> 

ASP.NET ValidationSummary Control Property

PropertyDescription
ControlToValidateSpecifies control name which needs to be validate.
DisplaySpecifies behavior of the error message.
EnableClientScriptSpecifies whether or not client-side validation is enabled.
EnabledSpecifies whether or not validation control is enabled or not.
ErrorMessageSpecifies error messageto be display in validation summary.
ForeColorSpecifies error message color.
IsValidIndicate if associate control passes validation or not.
SetFocusOnErrorSet focus on associate control if validation fails.
TextSpecifies text to be display if validation fails.
ValidationGroupSpecifies validation group name.
ValidateUpdate the isvalid propery.
ValidateGetValidationPropertyDetermineing validation property of a control, if it exists.
DisplayModeSpecifies display mode of validation summary.
EnableClientScriptSet a value that indicate whether the validation summary update itsels using client-side script.
ForeColorSet fourcolor of of control.
HeaderTextSet header text displaying at top of summary.
ShowErrorMessageSet a value to display summary in line.
ValidationGroupSet a group name of control.

ASP.NET ValidationSummary Grouping Example

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" 
Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>ASP.NET ValidationSummary Control With Grouping Example</title>
</head>
<body>
<form id="Form" runat="server">
<div style="font-family:Arial">
<asp:Label ID="lblTitle" runat="server" Font-Bold="True" Font-Size="Medium" 
    Font-Underline="True" Text="ASP.NET ValidationSummary Control With Grouping Example"></asp:Label>
<table cellpadding="4" cellspacing="2" border="0" width="450">
<tr><td colspan="2"><asp:ValidationSummary 
HeaderText="Error From Group1" ID="ValidationSummary1" runat="server" 
DisplayMode="BulletList" 
ShowMessageBox="true" ShowSummary="false" ForeColor="Red" ValidationGroup="Form1" /> 
<asp:ValidationSummary HeaderText="Error From Group2" ID="ValidationSummary2" 
runat="server" DisplayMode="BulletList" 
ShowMessageBox="true" ShowSummary="false" ForeColor="Red" ValidationGroup="Form2" />
</td></tr>

<tr><td><asp:Label ID="lblFirstName" runat="server" Text="First Name:  "></asp:Label></td>
<td><asp:TextBox ID="txtFName" runat="server" Width="174px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
    ControlToValidate="txtFName" Display="None" ValidationGroup="Form1"
    ErrorMessage="First Name is required field, can not be blank."></asp:RequiredFieldValidator></td></tr>

<tr><td><asp:Label ID="lblLastName" runat="server" Text="Last Name:  "></asp:Label></td>
<td><asp:TextBox ID="txtLName" runat="server" Width="174px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
    ControlToValidate="txtLName" Display="None" ValidationGroup="Form1" 
    ErrorMessage="Last Name is required field, can not be blank."></asp:RequiredFieldValidator></td></tr>

<tr><td><asp:Label ID="lblAccountNo" runat="server" Text="A/C No:  "></asp:Label></td>
<td><asp:TextBox ID="txtAccountNo" runat="server" Width="174px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
    ControlToValidate="txtAccountNo" Display="None" ValidationGroup="Form2" 
    ErrorMessage="Account# is required field, can not be blank."></asp:RequiredFieldValidator></td></tr>

<tr><td><asp:Label ID="lblPanNo" runat="server" Text="PAN No:  "></asp:Label></td>
<td><asp:TextBox ID="txtPanNo" runat="server" Width="174px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
    ControlToValidate="txtPanNo" Display="None" ValidationGroup="Form2" 
    ErrorMessage="PAN# is required field, can not be blank."></asp:RequiredFieldValidator></td></tr>

<tr><td> </td><td><asp:Button ID="btnSubmit1" runat="server" Font-Bold="True" 
    Font-Size="Small" Text="Submit Group1" ValidationGroup="Form1" />  
	<asp:Button ID="btnSubmit2" runat="server" Font-Bold="True" 
    Font-Size="Small" Text="Submit Group1" ValidationGroup="Form2" />  </td></tr>
</table> 
</div>   
</form>
</body>  
</html>

Above example will produce following output

RequiredFieldValidator

RegularExpressionValidator

RangValidator

CompareValidator

CustomValidator

ValidationSummary