Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the name of the validation group to which this validation control belongs.
public:
virtual property System::String ^ ValidationGroup { System::String ^ get(); void set(System::String ^ value); };
[System.Web.UI.Themeable(false)]
public virtual string ValidationGroup { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.ValidationGroup : string with get, set
Public Overridable Property ValidationGroup As 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.
The following code example demonstrates how to use the ValidationGroup property to assign a validation control to a group.
Important
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.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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>
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.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in