Populer Topics

Validation Summery Control

A Validation summery control is used to display a summary of all the validation error occurs in a web page.

The validation summery control enables us to display a list of all the validation error in a page in one location. This control is particularly usefully when working with large forms. If a user enter the wrong value from a form field located towards the end of the page, than the user might never see the error message.

If we use validation summery control so we can always display a list of error at the top of the form. In might have notice that each of the validation control include an error message property, we have not been use the error message property to represent the validation error message instead we have use the text property.

The different between the error message and text property is that any message that we assign to the error message property appear in the validation summery control and any message that we assign to the text property appear in the body of the page.

Normally we want to keep the message age for the text property short for example required.

The message assign to the error message property on the other hand should identify from field that has the error e.g. “Email Is Required”.

A Validation summery control provides following property.

Property Description
DisplayMode How to display the summery its value Bullet list, List, Single Paragraph.
HeaderText A Header in the validation summary control.
ShowMessageBox A Boolean value that’s specifies weather summery should be display in the message box or not.
ShowSummery A Boolean value that’s specifies weather the validation summery control should be display or hidden.
Enable  A Boolean value that specifies validation summery control should enable or not.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" 
Inherits="Codeplanex.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
    function NumberChecker(ObjectSource,ObjectArgs)
    {
        no = ObjectArgs.Value;
        if (no % 2)
        {
            ObjectArgs.IsValid = true;
        }
        else
        {
            ObjectArgs.IsValid = false;
        }
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
        <asp:CustomValidator ID="CV1" runat="server" ControlToValidate="txtNumber" 
             ErrorMessage="* It Required Only Even Number." ClientValidationFunction="NumberChecker" Display="None">
        </asp:CustomValidator>
        <asp:RequiredFieldValidator ID="R1" runat="server" ControlToValidate="txtNumber" 
             ErrorMessage="* Must Required A Value" Display="None"></asp:RequiredFieldValidator>
        <asp:ValidationSummary ID="VS1" runat="server" ShowMessageBox="true" ShowSummary="true" />
    </form>
</body>
</html>