Dynamicly Added Range Validator Acting Goofy

From: Jim Craddock via .NET 247 (anonymous_at_dotnet247.com)
Date: 09/15/04


Date: Wed, 15 Sep 2004 13:10:11 -0700

We add all the controls to our pages in the Page_load event. I recently noticed that the range validator doesn't fail in all cases when it should. If I set the min to 10 and the max to 1000 and add it dynamically, the value 50 will fail. If I change the 50 to 500 the value will pass. If I set the minimum at 10 and the max at 500, the value 50 will pass, but any value between 50 and 100 will fail, but 100 will pass - and it will only take values that are FACTORS of 50. So, 100 will pass and 101-149 will fail with 150 succeeding.

Is this a bug in .NET?

Here is the HTML except from the page:
<span id="_ctl3" controltovalidate="t_7" errormessage="The value for Page Size must be between 10 and 500<BR>" display="Dynamic" evaluationfunction="RangeValidatorEvaluateIsValid" maximumvalue="500" minimumvalue="10" style="color:Red;display:none;">The value for Page Size must be between 10 and 500<BR></span>

Here is the code that added it:
Public Shared Function AddRangeValidator(ByVal ColNumber As Integer, ByVal ColName As String, ByVal pl_hold As PlaceHolder, Optional ByVal minvalue As Integer = -1, Optional ByVal maxvalue As Integer = 999)
Dim RFV As New RangeValidator
If minvalue <> -1 Or maxvalue <> -1 Then
        RFV.ControlToValidate = "t_" & ColNumber.ToString
        RFV.ErrorMessage = "The value for " & ColName & " must be"
        If minvalue = -1 And maxvalue <> -1 Then
            RFV.ErrorMessage = RFV.ErrorMessage & " no more than " & maxvalue.ToString() & "<BR>"
            RFV.MaximumValue = maxvalue
        ElseIf maxvalue = -1 Then
            RFV.ErrorMessage = RFV.ErrorMessage & " at least " & minvalue.ToString() & "<BR>"
            RFV.MinimumValue = minvalue
        ElseIf minvalue <> -1 And maxvalue <> -1 Then
            RFV.ErrorMessage = RFV.ErrorMessage & " between " & minvalue.ToString() & " and " & maxvalue.ToString() & "<BR>"
            RFV.MaximumValue = maxvalue
            RFV.MinimumValue = minvalue
        End If
        RFV.ErrorMessage = RFV.ErrorMessage & vbCrLf & vbCrLf & vbCrLf
        RFV.Display = ValidatorDisplay.Dynamic
        pl_hold.Controls.Add(RFV)
End If
End Function

--------------------------------
From: Jim Craddock

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>FBxZYCY12EyadX2ADOVEVA==</Id>