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="txtCo mments"
Runat="server" />
<br />
<asp:TextBox
id="txtComments"
TextMode="MultiLine"
Columns="30"
Rows="2"
Runat="server" />
<custom:LengthValidator
id="valComments"
ControlToValidate="txtComm ents"
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.GetControlValidationVal ue(Me.Cont rolToValid ate)
If value.Length > _maximumLength Then
Return False
Else
Return True
End If
End Function
End Class
End Namespace
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="txtCo
Runat="server" />
<br />
<asp:TextBox
id="txtComments"
TextMode="MultiLine"
Columns="30"
Rows="2"
Runat="server" />
<custom:LengthValidator
id="valComments"
ControlToValidate="txtComm
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.GetControlValidationVal
If value.Length > _maximumLength Then
Return False
Else
Return True
End If
End Function
End Class
End Namespace
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
ASKER
Please close this question.