Validation Groups Demo : ValidationGroup « Validation « ASP.NET Tutorial






<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Validation Groups Demo</title>
  </head>
  <body>
    <form id="Form1" runat="server">
        Username:<br />
        <asp:TextBox id="usernameTextBox" runat="server" />
        <asp:RequiredFieldValidator id="usernameReq" 
            runat="server"
            ControlToValidate="usernameTextBox"
            ErrorMessage="Username is required!"
            SetFocusOnError="True" 
            ValidationGroup="Login" />
        Password:<br />
        <asp:TextBox id="passwordTextBox" 
            runat="server"
            TextMode="Password" />
        <asp:RequiredFieldValidator id="passwordReq" 
            runat="server"
            ControlToValidate="passwordTextBox"
            ErrorMessage="Password is required!"
            SetFocusOnError="True" 
            ValidationGroup="Login" />
        <asp:Button ID="loginButton" 
            runat="server" 
            Text="Log In" 
            ValidationGroup="Login" />
      <h1>Register</h1>
        Username:<br />
        <asp:TextBox id="newUserNameTextBox" runat="server" />
        <asp:RequiredFieldValidator id="newUserNameReq" 
            runat="server"
            ControlToValidate="newUserNameTextBox"
            ErrorMessage="Username is required!"
            SetFocusOnError="True" 
            ValidationGroup="Register" />
        Password:<br />
        <asp:TextBox id="newPasswordTextBox" 
            runat="server"
            TextMode="Password" />
        <asp:RequiredFieldValidator id="newPasswordReq" 
            runat="server"
            ControlToValidate="newPasswordTextBox"
            ErrorMessage="Password is required!"
            SetFocusOnError="True" 
            ValidationGroup="Register" />
        <asp:Button ID="registerButton" 
            runat="server" 
            Text="Register" 
            ValidationGroup="Register" />
      
    </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)