Using the ValidationGroup property (VB) : ValidationGroup « Validation « ASP.NET Tutorial






<%@ Page Language="VB" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Validation Groups</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>St. Louis .NET User Group</h1>
        Username:
        <asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>&nbsp; Password:
        <asp:TextBox ID="TextBox2" Runat="server" 
         TextMode="Password"></asp:TextBox>&nbsp;
        <asp:Button ID="Button1" Runat="server" Text="Login" 
         ValidationGroup="Login" />
            <br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" 
             ErrorMessage="* You must submit a username!"
             ControlToValidate="TextBox1" ValidationGroup="Login">
            </asp:RequiredFieldValidator>
            <br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Runat="server" 
             ErrorMessage="* You must submit a password!"
             ControlToValidate="TextBox2" ValidationGroup="Login">
            </asp:RequiredFieldValidator>

        
        <h2>Sign-up for the newsletter!</h2>
        Email:
        <asp:TextBox ID="TextBox3" Runat="server"></asp:TextBox>&nbsp;
        <asp:Button ID="Button2" Runat="server" Text="Sign-up" 
         ValidationGroup="Newsletter" />&nbsp;
            <br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
             Runat="server"
             ErrorMessage="* You must submit a correctly formatted email address!"
             ControlToValidate="TextBox3" ValidationGroup="Newsletter"
             ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
            </asp:RegularExpressionValidator>
            <br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Runat="server" 
             ErrorMessage="* You forgot your email address!"
             ControlToValidate="TextBox3" ValidationGroup="Newsletter">
            </asp:RequiredFieldValidator>
        
    </div>
    </form>
</body>
</html>








8.12.ValidationGroup
8.12.1.A validation group enables you to group related form fields together.
8.12.2.Validation Groups Demo
8.12.3.Group based validation (C#)
8.12.4.Two validation groups
8.12.5.Using the ValidationGroup property (VB)