ValidationSummary Example in ASP.NET

ValidationSummary Example in ASP.NET

ValidationSummary is one of the ASP.NET validation control. Which is useful for showing all errors in one place(see below screen shot). After using other validation controls, it is bit difficult to show the validation validation message, some times our screen design also damage while error message displaying. So, this is a good way to show all error messages at one shot.

This is one of the good ASP.NET Interview Question.

Output:
ValidationSummary Example in ASP.NET
ValidationSummary Example in ASP.NET

ASP.NET Code:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 40%;">
            <tr>
                <td>
                    <b>User Name:</b></td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="txtUserName" ErrorMessage="Please Enter User Name">*</asp:RequiredFieldValidator>
                </td>

            </tr>
            <tr>
                <td>
                    <b>First Name:</b></td>
                <td>
                    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="txtFirstName" ErrorMessage="Please Enter First Name">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Last Name:</b></td>
                <td>
                    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                        ControlToValidate="txtLastName" ErrorMessage="Please Enter Last Name">*</asp:RequiredFieldValidator>
                </td>

            </tr>
            <tr>
                <td>
                    <b>Sir Name:</b></td>
                <td>
                    <asp:TextBox ID="txtSirName" runat="server" 
                        ontextchanged="TextBox4_TextChanged"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                        ControlToValidate="txtSirName" ErrorMessage="Please enter sur name">*</asp:RequiredFieldValidator>
                </td>

            </tr>
            <tr>
                <td>
                    <b>Age:</b></td>
                <td>
                    <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                        ControlToValidate="txtAge" ErrorMessage="Please enter age">*</asp:RequiredFieldValidator>
                </td>

            </tr>
            <tr>
                <td>
                    <b>Date of Birth:</b></td>
                <td>
                    <asp:TextBox ID="txtDOB" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                        ControlToValidate="txtDOB" ErrorMessage="Please enter DOB">*</asp:RequiredFieldValidator>
                </td>

            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:Button ID="btnSubmit" runat="server" Text="Register" />
                </td>

            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:ValidationSummary ShowSummary="true" HeaderText="Please correct:" ID="ValidationSummary1" runat="server" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>





Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar