Using the RangeValidator

As we saw in the previous section, the CompareValidator can ensure that an input maintains some relation with either a constant value or the value in another user input. However, what if we wanted to ensure that an input was between a range of values? If we were to use the CompareValidator, we'd need to use two CompareValidators, one that did a GreaterThanEqual comparison on the lower bound of the range and one that did a LessThanEqual comparison on the upper bound of the range.

If the upper and lower bounds of the range are constant values, we can use a single RangeValidator instead of two CompareValidators. For the ValidationControlTestBed.aspx ASP.NET Web page, the age input is a suitable candidate for a RangeValidator, ...

Get SAMS Teach Yourself ASP.NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.