ImageButton.ValidationGroup Property
Definition
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 group of controls for which the ImageButton control causes validation when it posts back to the server.
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
Property Value
The group of controls for which the ImageButton control causes validation when it posts back to the server. The default value is an empty string ("").
Implements
- Attributes
Examples
The following code example demonstrates how to use the ValidationGroup property to specify the controls to validate when an ImageButton control posts back to the server. The page contains three text boxes to capture data from the user and three RequiredFieldValidator controls to ensure that the user does not leave a text box blank. The RequiredFieldValidator controls for the first two text boxes are in the PersonalInfoGroup
validation group and the RequiredFieldValidator control for the third text box is in the LocationInfoGroup
validation group. When ImageButton1
is clicked, only the controls in validation group PersonalInfoGroup
are validated. When ImageButton2
is clicked, only the control in validation group LocationInfoGroup
is validated.
<%@ 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 id="head1" runat="server">
<title>ImageButton.ValidationGroup Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageButton.ValidationGroup Example</h3>
<asp:label id="NameLabel"
text="Enter your name:"
runat="Server"
AssociatedControlID="NameTextBox">
</asp:label>
 
<asp:textbox id="NameTextBox"
runat="Server">
</asp:textbox>
 
<asp:requiredfieldvalidator id="RequiredFieldValidator1"
controltovalidate="NameTextBox"
validationgroup="PersonalInfoGroup"
errormessage="Enter your name."
runat="Server">
</asp:requiredfieldvalidator>
<br /><br />
<asp:label id="AgeLabel"
text="Enter your age:"
runat="Server"
AssociatedControlID="AgeTextBox">
</asp:label>
 
<asp:textbox id="AgeTextBox"
runat="Server">
</asp:textbox>
 
<asp:requiredfieldvalidator id="RequiredFieldValidator2"
controltovalidate="AgeTextBox"
validationgroup="PersonalInfoGroup"
errormessage="Enter your age."
runat="Server">
</asp:requiredfieldvalidator>
<br /><br />
<!--When ImageButton1 is clicked, only validation
controls that are a part of PersonalInfoGroup
are validated.-->
<asp:imagebutton id="ImageButton1"
alternatetext="Validate PersonalInfoGroup controls"
imageurl="Images/ImageButton1.JPG"
causesvalidation="true"
validationgroup="PersonalInfoGroup"
runat="Server" />
<br /><br />
<asp:label id="CityLabel"
text="Enter your city of residence:"
runat="Server"
AssociatedControlID="CityTextBox">
</asp:label>
 
<asp:textbox id="CityTextBox"
runat="Server">
</asp:textbox>
 
<asp:requiredfieldvalidator id="RequiredFieldValidator3"
controltovalidate="CityTextBox"
validationgroup="LocationInfoGroup"
errormessage="Enter a city name."
runat="Server">
</asp:requiredfieldvalidator>
<br /><br />
<!--When ImageButton2 is clicked, only validation
controls that are a part of LocationInfoGroup
are validated.-->
<asp:imagebutton id="ImageButton2"
alternatetext="Validate LocationInfoGroup controls"
imageUrl="Images/ImageButton2.JPG"
causesvalidation="true"
validationgroup="LocationInfoGroup"
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 id="head1" runat="server">
<title>ImageButton.ValidationGroup Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageButton.ValidationGroup Example</h3>
<asp:label id="NameLabel"
text="Enter your name:"
runat="Server" AssociatedControlID="NameTextBox">
</asp:label>
 
<asp:textbox id="NameTextBox"
runat="Server">
</asp:textbox>
 
<asp:requiredfieldvalidator id="RequiredFieldValidator1"
controltovalidate="NameTextBox"
validationgroup="PersonalInfoGroup"
errormessage="Enter your name."
runat="Server">
</asp:requiredfieldvalidator>
<br /><br />
<asp:label id="AgeLabel"
text="Enter your age:"
runat="Server"
AssociatedControlID="AgeTextBox">
</asp:label>
 
<asp:textbox id="AgeTextBox"
runat="Server">
</asp:textbox>
 
<asp:requiredfieldvalidator id="RequiredFieldValidator2"
controltovalidate="AgeTextBox"
validationgroup="PersonalInfoGroup"
errormessage="Enter your age."
runat="Server">
</asp:requiredfieldvalidator>
<br /><br />
<!--When ImageButton1 is clicked, only validation
controls that are a part of PersonalInfoGroup
are validated.-->
<asp:imagebutton id="ImageButton1"
alternatetext="Validate PersonalInfoGroup controls"
imageurl="Images/ImageButton1.JPG"
causesvalidation="true"
validationgroup="PersonalInfoGroup"
runat="Server" />
<br /><br />
<asp:label id="CityLabel"
text="Enter your city of residence:"
runat="Server"
AssociatedControlID="CityTextBox">
</asp:label>
 
<asp:textbox id="CityTextBox"
runat="Server">
</asp:textbox>
 
<asp:requiredfieldvalidator id="RequiredFieldValidator3"
controltovalidate="CityTextBox"
validationgroup="LocationInfoGroup"
errormessage="Enter a city name."
runat="Server">
</asp:requiredfieldvalidator>
<br /><br />
<!--When ImageButton2 is clicked, only validation
controls that are a part of LocationInfoGroup
are validated.-->
<asp:imagebutton id="ImageButton2"
alternatetext="Validate LocationInfoGroup controls"
imageUrl="Images/ImageButton2.JPG"
causesvalidation="true"
validationgroup="LocationInfoGroup"
runat="Server" />
</form>
</body>
</html>
Remarks
Validation groups allow you to assign validation controls on a page to a specific category. Each validation group can be validated independently of other validation groups on the page. Use the ValidationGroup property to specify the name of the validation group for which the ImageButton control causes validation when it posts back to the server. This property has an effect only when the value of the CausesValidation property is set to true
. When you specify a value for the ValidationGroup property, only the validation controls that are part of the specified group are validated when the ImageButton control posts back to the server. If you do not specify a value for this property and the CausesValidation property is set to true
, all validation controls on the page that are not assigned to a validation group are validated when the control posts back to the server.
This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins.