Click here to Skip to main content
15,884,838 members
Articles / Web Development / ASP.NET

ASP.NET Server Side Messages & Client Validation Message Handling.

Rate me:
Please Sign up or sign in to vote.
4.67/5 (30 votes)
25 May 2011CPOL5 min read 109.4K   3.5K   73  
Show different type of Client Side and Server side messages in a Modal box.
<%@ Page Title="" Language="C#" MasterPageFile="~/Layout.Master" AutoEventWireup="true"
    CodeBehind="MultipleValidationSummaryTest.aspx.cs" Inherits="ValidationMessage.MultipleValidationSummaryTest" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="content" class="round" style="height: 500px">
        <h1>
            Multiple Validation Group Test</h1>
        <br />
        <fieldset>
            <legend>Validation Group 1</legend>
            <table>
                <tr>
                    <td>
                        Required Field
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox1" ValidationGroup="V1" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter the value of 'Required Field' of Group 1"
                            ControlToValidate="TextBox1" Display="None" ValidationGroup="V1"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Range Validator&nbsp;
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox2" runat="server" ValidationGroup="V1"></asp:TextBox>
                        <asp:RangeValidator ID="RangeValidator1" Display="None" ValidationGroup="V1" runat="server"
                            ErrorMessage="Invalid Range of Group 1. Valid [1-1000]" ControlToValidate="TextBox2" MaximumValue="1000"
                            MinimumValue="1" Type="Integer"></asp:RangeValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Email Regular Expression Validator
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox3" runat="server" ValidationGroup="V1"></asp:TextBox>
                        <asp:RegularExpressionValidator Display="None" ID="RegularExpressionValidator1" ValidationGroup="V1"
                            ControlToValidate="TextBox3" runat="server" ErrorMessage="Invalid Email of Group 1" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
            </table>
            <br />
            <div>
                <center>
                    <asp:Button ID="Button1" ValidationGroup="V1" runat="server" OnClick="Button1_Click"
                        OnClientClick="ValidateJs('V1');" Text="Post" />
                </center>
            </div>
        </fieldset>
        <fieldset>
            <legend>Validation Group 2</legend>
            <table>
                <tr>
                    <td>
                        Required Field
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox4" ValidationGroup="V2" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter the value of 'Required Field' of Group 2"
                            ControlToValidate="TextBox4" Display="None" ValidationGroup="V2"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Range Validator&nbsp;
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox5" runat="server" ValidationGroup="V2"></asp:TextBox>
                        <asp:RangeValidator ID="RangeValidator2" Display="None" ValidationGroup="V2" runat="server"
                            ErrorMessage="Invalid Range of Group 2. Valid [1-1000]" ControlToValidate="TextBox5" MaximumValue="1000"
                            MinimumValue="1" Type="Integer"></asp:RangeValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Email Regular Expression Validator
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox6" runat="server" ValidationGroup="V2"></asp:TextBox>
                        <asp:RegularExpressionValidator Display="None" ID="RegularExpressionValidator2" ValidationGroup="V2"
                            ControlToValidate="TextBox6" runat="server" ErrorMessage="Invalid Email of Group 2" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
            </table>
            <div>
                <center>
                    <asp:Button ID="Button2" ValidationGroup="V2" runat="server" OnClick="Button1_Click" OnClientClick="ValidateJs('V2');"
                        Text="Post" />
                </center>
            </div>
        </fieldset>
    </div>
</asp:Content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Its me Smile | :)

Comments and Discussions