VB.net Tutorials with Examples

VB.Net Projects

VB.Net Project 1

adplus-dvertising
Custom Validator control
Previous Home Next

It is used to validate user input based on the user defined functionality. OR Custom validator control is used to capture the validation that cannot be handled by the validator controls provided by ASP.NET. Here user is at the freedom to define his own custom method, both Client side and Server side.

CustomValidator is the only validator control which has the capability to validate the user input at the client side and also at the server side. Other than the CustomValidator, all the controls will validate the user input at the client side.

Property

ClientValidationFunction Specifies the JavaScript function name, which provides the definition to validate the user input at the client side

Event

ServerValidate The code written within this event will be used to validate the user input at the server side.

.aspx Code

Custom text:<br />
<asp:TextBox runat="server" id="txtCustom" />
<asp:CustomValidator runat="server" id="cusCustom" 
controltovalidate="txtCustom" 
onservervalidate="cusCustom_ServerValidate"
errormessage="The text must be exactly 8 characters long!" />
<br /><br />

.VB CODE

Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, 
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) 
Handles CustomValidator1.ServerValidate
If args.Value.Length = 8 Then
 args.IsValid = True
Else
args.IsValid = False
End If
End Sub

ValidateEmptyText: is a boolean attribute that if set to true, the input control will be validated even if it is empty.

ClientValidationFunction: contains name of client validation function.

OnServerValidate: contains name of server validation function.

Previous Home Next