Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
BaseValidator Class
 ValidationGroup Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
BaseValidator..::.ValidationGroup Property

Updated: November 2007

Gets or sets the name of the validation group to which this validation control belongs.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Visual Basic (Declaration)
<ThemeableAttribute(False)> _
Public Overridable Property ValidationGroup As String
Visual Basic (Usage)
Dim instance As BaseValidator
Dim value As String

value = instance.ValidationGroup

instance.ValidationGroup = value
C#
[ThemeableAttribute(false)]
public virtual string ValidationGroup { get; set; }
Visual C++
[ThemeableAttribute(false)]
public:
virtual property String^ ValidationGroup {
    String^ get ();
    void set (String^ value);
}
J#
/** @property */
/** @attribute ThemeableAttribute(false) */
public String get_ValidationGroup()
/** @property */
/** @attribute ThemeableAttribute(false) */
public  void set_ValidationGroup(String value)
JScript
public function get ValidationGroup () : String
public function set ValidationGroup (value : String)
ASP.NET
<asp:BaseValidator ValidationGroup="String" />

Property Value

Type: System..::.String

The name of the validation group to which this validation control belongs. The default is an empty string (""), which indicates that this property is not set.

ASP.NET provides many controls that have the ability to post back to the server. When one of these controls has its CausesValidation property set to true, validation is performed when the control posts back to server. The following controls have the ability to post back to the server:

Note:

Some of these controls post back to the server only when the AutoPostBack property is set to true.

These controls each have a ValidationGroup property that, when set, validates only the validation controls within the specified group when the control triggers a post back to the server. Use the ValidationGroup property to assign a validation control to a validation group. The Page class also exposes a GetValidators method and a Validate method that accept a ValidationGroup input parameter.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.

TopicLocation
Walkthrough: Validating User Input in a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Validating User Input in a Web Forms PageBuilding Applications with Visual Web Developer

The following code example demonstrates how to use the ValidationGroup property to assign a validation control to a group.

Security Note:

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

Visual Basic
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>BaseValidator ValidationGroup Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>BaseValidator ValidationGroup Example</h3>

      Please enter your name:<br/>
      <asp:textbox id="NameTextBox" 
        runat="server"/>

      <asp:requiredfieldvalidator id="NameTextBoxRequiredValidator" 
        controltovalidate="NameTextBox"
        display="Dynamic" 
        text="Please enter your name."
        validationgroup="UserInfoGroup" 
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        validationgroup="UserInfoGroup" 
        runat="server"/>

      <hr/>

      Please enter a search topic:<br/>
      <asp:textbox id="SearchTextBox" 
        runat="server"/>

      <asp:requiredfieldvalidator id="SearchTextBoxRequiredValidator" 
        controltovalidate="SearchTextBox"
        display="Dynamic" 
        text="Please enter a topic."
        validationgroup="SearchGroup"
        runat="server"/>

      <br /><br />

      <asp:button id="SearchButton"
        text="Search"
        validationgroup="SearchGroup"
        runat="server"/>

    </form>
  </body>
</html>


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>BaseValidator ValidationGroup Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>BaseValidator ValidationGroup Example</h3>

      Please enter your name:<br/>
      <asp:textbox id="NameTextBox" 
        runat="server"/>

      <asp:requiredfieldvalidator id="NameTextBoxRequiredValidator" 
        controltovalidate="NameTextBox"
        display="Dynamic" 
        text="Please enter your name."
        validationgroup="UserInfoGroup" 
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        validationgroup="UserInfoGroup" 
        runat="server"/>

      <hr/>

      Please enter a search topic:<br/>
      <asp:textbox id="SearchTextBox" 
        runat="server"/>

      <asp:requiredfieldvalidator id="SearchTextBoxRequiredValidator" 
        controltovalidate="SearchTextBox"
        display="Dynamic" 
        text="Please enter a topic."
        validationgroup="SearchGroup"
        runat="server"/>

      <br /><br />

      <asp:button id="SearchButton"
        text="Search"
        validationgroup="SearchGroup"
        runat="server"/>

    </form>
  </body>
</html>


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker