Validation Summary Control in Asp.Net C#


The ValidationSummary control does not perform any validation but shows a summary of all errors in the page.
 The summary displays the values of the ErrorMessage property of all validation controls that failed validation.


                             Html Coding

<html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">

            <asp:Label ID="Label2" runat="server" Text="Email ID"></asp:Label>
                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                    runat="server" ControlToValidate="txtEmail"
                    ErrorMessage="Invalid Email ID"

            <asp:Label ID="Label1" runat="server" Text="Password"></asp:Label>
                <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
                <asp:CompareValidator ID="CompareValidator1"
                    runat="server" ControlToCompare="txtConfirmPassword"
                    ControlToValidate="txtPassword" SetFocusOnError="True"></asp:CompareValidator>
            <asp:Label ID="Label3" runat="server" Text="Confirm Password"></asp:Label>
                <asp:TextBox ID="txtConfirmPassword" runat="server"></asp:TextBox>
                <asp:CompareValidator ID="CompareValidator2"
                     runat="server" ControlToCompare="txtPassword"
                    ErrorMessage="Password Not Same" SetFocusOnError="True"></asp:CompareValidator>
            <asp:Label ID="Label4" runat="server" Text="Country"></asp:Label>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                    runat="server" ControlToValidate="TextBox1"
                    ErrorMessage="Fill Country Name" SetFocusOnError="True"></asp:RequiredFieldValidator>
        <tr><td colspan="2">
            <asp:Button ID="Button1" runat="server" Text="Save" />

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


 we can display validation errors summary inline of a web page or a message box or both by using ShowMessageBox and ShowSummary property value true or false.

The following two mutually inclusive properties list out the error message:

  • ShowSummary: shows the error messages in specified format.
  • ShowMessageBox: shows the error messages in a separate window.

we can display validation messages as bulleted list, single paragraph or only list based on DisplayMode. we can set a header text for validation summary.

First - Add New - WebForm - Select Validation Controls  Required - Next-Select - Validation Summary

First Select -  Regular Expression Validation  - Set Property  & setfocusError=True

Next  - Select  Compare  Validation  - Set Property  & setfocusError=True


Next   - Select  Compare  Validation  - Set Property  & setfocusError=True

Next - Select  Required  Validation  - Set Property  & setfocusError=True

Next  - Validation Summary  Does not Change Anything


        Give to  Valid Entries  Does Not Show Error PopUp

Next - Press F5 run the program  - Enter the Invalid Values - Show Error Message related  Validation  Expressions - last enter Save Button  Validation summary Error Message Show


Post a Comment