Using OrComposite Validator as a Object

Topics: Validation Application Block
Mar 3, 2008 at 7:52 PM
I'm trying to use the OrCompositeValidator as an object, but when I pass a ValidationResults it doesn't validate the collection of validators" . What object should I use to collect all validators and then pass the object to OrComposite . Please see my code example below:

Dim objValidateRow As New ValidationResults

'*** Loop though object properties and collect results ***

objValidateRow = valStringLengthValidator(Property Value, LowerBound, UpperBound, Message)

objValidateRow = valOrCompositeValidator(objValidateRow)


'*** End of Loop ****

If CheckValidationResults(objOverAllValidate) = RESULTS_OK Then
Return True
End If

Public Function valOrCompositeValidator(ByVal objValidationResults As ValidationResults)

Dim myValAttributes As New OrCompositeValidator
myValAttributes.MessageTemplate = "OrCompositeValidator"
Return myValAttributes.Validate(objValidationResults)

End Function

Public Function valStringLengthValidator(ByVal strValue As String, ByVal intUpper As Integer, _
ByVal intLower As Integer, ByVal strMessage As String)
Dim myValAttributes As New StringLengthValidator(intUpper, intLower)
myValAttributes.MessageTemplate = strMessage
Return myValAttributes.Validate(strValue)
End Function

Private Function CheckValidationResults(ByVal results As ValidationResults) As Boolean

Dim resultsOK As Boolean = True
If (Not results.IsValid) Then
resultsOK = False
For Each result As ValidationResult In results
End If
Return resultsOK

End Function

Any feedback would help, thanks.