PropertyComparisonValidator problem

Topics: Validation Application Block
Mar 2, 2009 at 2:55 AM
hi experts,

below is my validationClass, when i test the change password page, i hit an error

No public readable property with name "NewPasswords" could be found for type "validationClass".

   <StringLengthValidator(1, 10, MessageTemplateResourceType:=GetType(StarOne), MessageTemplateResourceName:="profile_update_password_new_callout")> _
    ReadOnly Property NewPassword(ByVal _NewPassword As String) As String

        Get
            Return _NewPassword
        End Get

    End Property

    <PropertyComparisonValidator("NewPassword", ComparisonOperator.Equal, MessageTemplateResourceType:=GetType(StarOne), MessageTemplateResourceName:="profile_update_password_confirm_compare_callout")> _
    ReadOnly Property ConfirmPassword(ByVal _ConfirmPassword As String) As String

        Get
            Return _ConfirmPassword
        End Get

    End Property

anyone know how this can be fixed?
Mar 2, 2009 at 5:12 AM
I think you might have mistyped the property name.  Your code shows that it is "NewPassword" but the error specifies that it is looking for a "NewPasswords" property.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Mar 2, 2009 at 5:20 AM
oh sorry, when i pasted the error i have tried to change the stuff but diddn't copy the new code :P

the error should say..

No public readable property with name "NewPassword" could be found for type "validationClass".
Mar 2, 2009 at 5:22 AM
i did manage to fix the error by coding like the following...

    Dim _NewPassword As String = Nothing
    <StringLengthValidator(1, 10, MessageTemplateResourceType:=GetType(StarOne), MessageTemplateResourceName:="profile_update_password_new_callout")> _
    Public Property NewPassword() As String

        Get
            Return _NewPassword
        End Get

        Set(ByVal _value As String)
            _NewPassword = _value
        End Set

    End Property

    Dim _ConfirmPassword As String = Nothing
    <PropertyComparisonValidator("NewPassword", ComparisonOperator.Equal, MessageTemplateResourceType:=GetType(StarOne), MessageTemplateResourceName:="profile_update_password_confirm_compare_callout")> _
    Public Property ConfirmPassword() As String

        Get
            Return _ConfirmPassword
        End Get

        Set(ByVal _value As String)
            _ConfirmPassword = _value
        End Set

    End Property

not sure why this works and the code above doesn't... :S


Mar 2, 2009 at 5:29 AM
That looks like it has something to do with the visibility of the property.  I'm using C#, if I set the properties to private, the validation doesn't work, it always returns true and I'm not getting the error you previously encountered.  But if I set the properties both to public, it works as expected.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Mar 2, 2009 at 5:36 AM
i take it your code look like this?

[StringLengthValidator(1, 10, MessageTemplateResourceType = typeof(StarOne), MessageTemplateResourceName = "profile_update_password_new_callout")]
public string NewPassword {
    
    get { return _NewPassword; }
}


[PropertyComparisonValidator("NewPassword", ComparisonOperator.Equal, MessageTemplateResourceType = typeof(StarOne), MessageTemplateResourceName = "profile_update_password_confirm_compare_callout")]
public string ConfirmPassword {
    
    get { return _ConfirmPassword; }
}


Mar 2, 2009 at 5:56 AM
Yes.
Mar 2, 2009 at 5:59 AM
strange that it doesn't work in VB.Net :S
Mar 2, 2009 at 6:06 AM
Guess that it's just one of those differences between the two.  Anyway, I assume you could just resolve the problem by adding the public modifier and not having to remove the ReadOnly attribute.


 Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com