Gets or sets the name of the custom client-side script function used for validation.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

Syntax
Visual Basic (Declaration)
<ThemeableAttribute(False)> _
Public Property ClientValidationFunction As String
Dim instance As CustomValidator
Dim value As String
value = instance.ClientValidationFunction
instance.ClientValidationFunction = value
[ThemeableAttribute(false)]
public string ClientValidationFunction { get; set; }
[ThemeableAttribute(false)]
public:
property String^ ClientValidationFunction {
String^ get ();
void set (String^ value);
}
/** @property */
public String get_ClientValidationFunction ()
/** @property */
public void set_ClientValidationFunction (String value)
public function get ClientValidationFunction () : String
public function set ClientValidationFunction (value : String)
Property Value
The name of the custom client script function used for validation. The default value is
String.Empty, which indicates that this property is not set.
Note |
|---|
| The function name should not include any parentheses or parameters. |

Remarks
Set this property to the name of the function that performs the client-side validation.
Because the client validation function runs on the target browser, the function must be written using a scripting language supported by the browser, such as JScript or VBScript.
This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.

Example
The following code example demonstrates how to use the ClientValidationFunction property to specify the name of the function that performs client-side validation. The validation function checks for even numbers.
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
Sub ValidateBtn_OnClick(sender As Object, e As EventArgs)
' Display whether the page passed validation.
If Page.IsValid Then
Message.Text = "Page is valid."
Else
Message.Text = "Page is not valid!"
End If
End Sub
Sub ServerValidation(source As Object, args As ServerValidateEventArgs)
Try
' Test whether the value entered into the text box is even.
Dim num As Integer = Integer.Parse(args.Value)
args.IsValid = ((num mod 2) = 0)
Catch ex As Exception
args.IsValid = false
End Try
End Sub
</script>
</head>
<body>
<form runat="server">
<h3>CustomValidator ServerValidate Example</h3>
<asp:Label id="Message"
Text="Enter an even number:"
Font-Name="Verdana"
Font-Size="10pt"
runat="server"/>
<p>
<asp:TextBox id="Text1"
runat="server" />
<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
<p>
<asp:Button id="Button1"
Text="Validate"
OnClick="ValidateBtn_OnClick"
runat="server"/>
</form>
</body>
</html>
<script language="vbscript">
<!--
Sub ClientValidate(source, arguments)
If (arguments.Value mod 2) = 0 Then
arguments.IsValid=true
Else
arguments.IsValid=false
End If
End Sub
' -->
</script>
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void ValidateBtn_OnClick(object sender, EventArgs e)
{
// Display whether the page passed validation.
if (Page.IsValid)
{
Message.Text = "Page is valid.";
}
else
{
Message.Text = "Page is not valid!";
}
}
void ServerValidation(object source, ServerValidateEventArgs args)
{
try
{
// Test whether the value entered into the text box is even.
int i = int.Parse(args.Value);
args.IsValid = ((i%2) == 0);
}
catch(Exception ex)
{
args.IsValid = false;
}
}
</script>
</head>
<body>
<form runat="server">
<h3>CustomValidator ServerValidate Example</h3>
<asp:Label id="Message"
Text="Enter an even number:"
Font-Name="Verdana"
Font-Size="10pt"
runat="server"/>
<p>
<asp:TextBox id="Text1"
runat="server" />
<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
<p>
<asp:Button id="Button1"
Text="Validate"
OnClick="ValidateBtn_OnClick"
runat="server"/>
</form>
</body>
</html>
<script language="vbscript">
<!--
Sub ClientValidate(source, arguments)
If (arguments.Value mod 2) = 0 Then
arguments.IsValid=true
Else
arguments.IsValid=false
End If
End Sub
' -->
</script>

Platforms
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information
.NET Framework
Supported in: 2.0, 1.1, 1.0

See Also