Link to home
Create AccountLog in
Avatar of timothyrmyers
timothyrmyers

asked on

Error using custom validation control

When I run the code below I get the error :  Unknown server tag 'custom:LengthValidator'.
I have tried adding Assembly = "myProject" to the Register tag and that didn't hep.  I'm using Visual Studio 2010 and ASP.Net 4.0.  This is an example from ASP.Net 4 Unleashed.  

ShowLengthValidator.aspx is below:  

<%@ Page Language="VB" %>
<%@ Register TagPrefix="custom" Namespace="myControls" %>
<!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>Show Length Validator</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    <asp:Label
        id="lblComments"
        Text="Comments:"
        AssociatedControlID="txtComments"
        Runat="server" />
    <br />
    <asp:TextBox
        id="txtComments"
        TextMode="MultiLine"
        Columns="30"
        Rows="2"
        Runat="server" />
    <custom:LengthValidator
        id="valComments"
        ControlToValidate="txtComments"
        Text="(Must be less than 10 characters)"
        MaximumLength="10"
        Runat="server" />
   
    <br /><br />
   
    <asp:Button
        id="btnSubmit"
        Text="Submit"
        Runat="server" />
   
    </div>
    </form>
</body>
</html>

LengthValidator.vb code is below:

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace myControls

    ''' <summary>
    ''' Validates the length of an input field
    ''' </summary>
    Public Class LengthValidator
        Inherits BaseValidator

        Dim _maximumLength As Integer = 0

        Public Property MaximumLength() As Integer
            Get
                Return _maximumLength
            End Get
            Set(ByVal Value As Integer)
                _maximumLength = value
            End Set
        End Property

        Protected Overrides Function EvaluateIsValid() As Boolean
            Dim value As String = Me.GetControlValidationValue(Me.ControlToValidate)
            If value.Length > _maximumLength Then
                Return False
            Else
                Return True
            End If
        End Function
    End Class
End Namespace
ASKER CERTIFIED SOLUTION
Avatar of lenordiste
lenordiste
Flag of France image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Amandeep Singh Bhullar
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Avatar of timothyrmyers
timothyrmyers

ASKER

Please close this question.