aspnet
  1. aspnet-validationsummary

ValidationSummary - ( ASP.NET Validation )

ASP.NET provides a validation feature that can be used to validate user input on a web page. ValidationSummary control summarizes all validation errors in a single location. In this page, we'll discuss how to use ValidationSummary in ASP.NET.

Syntax

Here's the syntax for the ValidationSummary control:

<asp:ValidationSummary ID="ValidationSummary1" runat="server" 
    DisplayMode="BulletList/CssClass/List" HeaderText="Validation Errors" 
    ShowMessageBox="true/false" EnableClientScript="true/false" />
  • ID - Specifies the ID of the ValidationSummary control.
  • runat - Specifies that the control is a server-side control.
  • DisplayMode - Specifies how the validation errors are displayed. It has three options: BulletList, CssClass, or List.
  • HeaderText - Specifies the text to display as the header of the validation summary.
  • ShowMessageBox (optional) - Specifies whether to show a message box displaying the validation summary when the user submits the form.
  • EnableClientScript (optional) - Specifies whether to use client-side scripting to validate user input.

Example

Here is an example of how to use the ValidationSummary control in an ASP.NET page.

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtName"
    Text="Name is required" />

<asp:ValidationSummary ID="ValidationSummary1" runat="server" />

In this example, we have a text box that requires a value and a RequiredFieldValidator control that is used to validate the text box. The ValidationSummary control is used to display all validation errors in a single location.

Output

When a validation error occurs, the ValidationSummary control displays a summary of all validation errors in the specified format. If ShowMessageBox is set to true, it also displays a message box showing the validation summary.

Explanation

The ValidationSummary control is used to display a summary of all validation errors occurred on an ASP.NET page. This control can be used to display validation errors in a single location of the page for ease of use. We need to use ValidationSummary control with other validation controls such as RequiredFieldValidator, RangeValidator, RegularExpressionValidator, and others.

Use

The ValidationSummary control is very useful for displaying a summary of all validation errors in a single location on an ASP.NET page. This control helps users to know where the validation errors occurred on the page and what they need to do to correct them.

Important Points

  • The ValidationSummary control is used to display a summary of validation errors that occurred on an ASP.NET page.
  • ValidationSummary control can be used with other validation controls.
  • We can customize the appearance of the display format by using DisplayMode property.

Summary

In this page, we discussed the ValidationSummary control in ASP.NET. We covered the syntax, example, output, explanation, important points, and the use of ValidationSummary. By using the ValidationSummary control in an ASP.NET page, we can display a summary of validation errors occurred on the page in a single location. This control plays an important role in the validation of user inputs.

Published on: