Asp.Net ValidationSummary Code Example in C# VB.Net

The ValidationSummary control allow us to summarize the error messages from all validation controls on a Web page in a single location like the top of the page or bottom of the page. The summary can be displayed as a list, a bulleted list, or a single paragraph, based on the value of the DisplayMode property. The error message displayed in the ValidationSummary control for each validation control on the page is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed in the ValidationSummary control for that validation control. You can also specify a custom title in the heading section of the ValidationSummary control by setting the HeaderText property.

Some important properties of ValidationSummary control:
DisplayMode: We can display messages in the BulletList, List or SingleParagraph.
ShowSummary: Set this value to true in order to use the ValidationSummary control.
ShowMessageBox: Whether you want to display error messages in the page or in a MessageBox.
HeaderText: specify a custom title in the heading section of the ValidationSummary control.
SkinID: You can mention a Skin here.
ValidationGroup: If you need to validate group wise controls.

To do the Example use the Below HTML code:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<table>
<tr><td colspan="2"><asp:ValidationSummary id="valSum" 
                          DisplayMode="BulletList"
                          forecolor="Red"
                          EnableClientScript="true"
                          Font-Bold="true"
                          HeaderText="Please Correct following Errors:"
                          runat="server"/></td></tr>
<tr><td>Name:</td><td><asp:TextBox ID="txtName" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Name is Required !!" ControlToValidate="txtName" display="None"></asp:RequiredFieldValidator></td></tr>
<tr><td>Email:</td><td><asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Email is Required !!" ControlToValidate="txtEmail" display="None"></asp:RequiredFieldValidator> </td></tr>
<tr><td>Mobile:</td><td><asp:TextBox ID="txtMobile" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Mobile No is Required !!" ControlToValidate="txtMobile" display="None"></asp:RequiredFieldValidator><asp:comparevalidator ID="Comparevalidator1" errormessage="Mobile must be Number !!" display="None" type="Integer" Operator="DataTypeCheck" controltovalidate="txtMobile" runat="server"></asp:comparevalidator></td></tr>
<tr><td></td><td><asp:Button ID="Button1" runat="server" Text="Button" /></td></tr>
</table>
</asp:Content>

Note: Use Display=”None” property of all Validators. This will hide original error message of Validation controls.

Output/Outcome:
ValidationSummary Code Example in Asp.Net Csharp VB.Net

Complete syntax of a ValidationSummary control:

<asp:ValidationSummary
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CssClass="string"
    DisplayMode="List|BulletList|SingleParagraph"
    EnableClientScript="True|False"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    HeaderText="string"
    Height="size"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    ShowMessageBox="True|False"
    ShowSummary="True|False"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    ToolTip="string"
    ValidationGroup="string"
    Visible="True|False"
    Width="size"
/>

Ref: MSISDN

Download Code Example C#        Download Code Example VB.Net

Posted in .Net, Asp.net, C#, VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

     

*