Gets or sets the input control to validate.
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
<TypeConverterAttribute(GetType(ValidatedControlConverter))> _
<ThemeableAttribute(False)> _
Public Property ControlToValidate As String
Dim instance As BaseValidator
Dim value As String
value = instance.ControlToValidate
instance.ControlToValidate = value
[TypeConverterAttribute(typeof(ValidatedControlConverter))]
[ThemeableAttribute(false)]
public string ControlToValidate { get; set; }
[TypeConverterAttribute(typeof(ValidatedControlConverter))]
[ThemeableAttribute(false)]
public:
property String^ ControlToValidate {
String^ get ();
void set (String^ value);
}
public function get ControlToValidate () : String
public function set ControlToValidate (value : String)
<asp:BaseValidator ControlToValidate="String" />
Use the ControlToValidate property to specify the input control to validate. This property must be set to the ID of an input control for all validation controls except the CustomValidator control, which can be left blank. If you do not specify a valid input control, an exception will be thrown when the page is rendered. The ID must refer to a control within the same container as the validation control. It must be in the same page or user control, or it must be in the same template of a templated control.
The standard controls that can be validated are:
All validation controls, except the RequiredFieldValidator control, will pass validation if the input control specified by the ControlToValidate property contains no text. If you are using a CustomValidator control, the client-side and server-side validation functions are not called either.
This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.
The following code example demonstrates how to use the ControlToValidate property to specify the input control to validate.
<%@ Page Language="VB" AutoEventWireup="False" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
If Page.IsValid Then
MessageLabel.Text = "Page submitted successfully."
Else
MessageLabel.Text = "There is an error on the page."
End If
End Sub
</script>
<html >
<head runat="server">
<title>Validator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Validator Example</h3>
Enter a number from 1 to 10.
<asp:textbox id="NumberTextBox"
runat="server"/>
<asp:rangevalidator id="NumberCompareValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
type="Integer"
display="Dynamic"
errormessage="Please enter a value from 1 to 10."
maximumvalue="10"
minimumvalue="1"
text="*"
runat="server"/>
<asp:requiredfieldvalidator id="TextBoxRequiredValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
display="Dynamic"
errormessage="Please enter a value."
text="*"
runat="server"/>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
runat="server"/>
<br /><br />
<asp:label id="MessageLabel"
runat="server"/>
<br /><br />
<asp:validationsummary
id="ErrorSummary"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
if (Page.IsValid)
{
MessageLabel.Text = "Page submitted successfully.";
}
else
{
MessageLabel.Text = "There is an error on the page.";
}
}
</script>
<html >
<head runat="server">
<title>Validator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Validator Example</h3>
Enter a number from 1 to 10.
<asp:textbox id="NumberTextBox"
runat="server"/>
<asp:rangevalidator id="NumberCompareValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
type="Integer"
display="Dynamic"
errormessage="Please enter a value from 1 to 10."
maximumvalue="10"
minimumvalue="1"
text="*"
runat="server"/>
<asp:requiredfieldvalidator id="TextBoxRequiredValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
display="Dynamic"
errormessage="Please enter a value."
text="*"
runat="server"/>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
onclick="Button_Click"
runat="server"/>
<br /><br />
<asp:label id="MessageLabel"
runat="server"/>
<br /><br />
<asp:validationsummary
id="ErrorSummary"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="JScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
function Button_Click(sender, e : EventArgs)
{
if (Page.IsValid)
{
MessageLabel.Text = "Page submitted successfully.";
}
else
{
MessageLabel.Text = "There is an error on the page.";
}
}
</script>
<html >
<head runat="server">
<title>Validator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Validator Example</h3>
Enter a number from 1 to 10.
<asp:textbox id="NumberTextBox"
runat="server"/>
<asp:rangevalidator id="NumberCompareValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
type="Integer"
display="Dynamic"
errormessage="Please enter a value from 1 to 10."
maximumvalue="10"
minimumvalue="1"
text="*"
runat="server"/>
<asp:requiredfieldvalidator id="TextBoxRequiredValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
display="Dynamic"
errormessage="Please enter a value."
text="*"
runat="server"/>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
onclick="Button_Click"
runat="server"/>
<br /><br />
<asp:label id="MessageLabel"
runat="server"/>
<br /><br />
<asp:validationsummary
id="ErrorSummary"
runat="server"/>
</form>
</body>
</html>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, 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, 1.1, 1.0
Reference