Vb.net – Custom Validator validation not firing for textbox

asp.netvb.net

I have created a custom validator for maximum characters for a multiline textbox in ASP.Net.

Below is the code that I am using.

<asp:CustomValidator ID="cvPersonality" runat="server" ControlToValidate="txtPersonality"
    Display="Dynamic" ErrorMessage="*Maximum Characters 200" 
    OnServerValidate="cvPersonality_ServerValidate"></asp:CustomValidator>

Protected Sub cvPersonality_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
    Dim strDesc As String = Me.txtPersonality.Text
    If Len(strDesc) > 200 Then
     args.IsValid = False
    Else
     args.IsValid = True
    End If
End Sub

Thanks

Best Solution

Remember to set this property on the CustomValidator...

ValidateEmptyText="True"
Related Question