In ASP.Net, how do I limit validation messages to only one?
Rule: User must put in a number between 0 and 1000.
Current [undesired] Behavior:
User types 1001: validator says “Please put in a non-negative number beneath 1000”
User types -1: validator says “Please put in a non-negative number beneath 1000”
Desired Behavior:
User types 1001: validator says “Please put in a number beneath 1000”
User types -1: validator says “Please put in a non-negative number”
In other words, how can I use two asp:RangeValidators whose disallowed values intersect but only turn on the desired one? I do not want to handle a ServerValidate event on the server.
Is it doable without client-side code?
You can use a CompareValidator to checks whether the value is less than zero and a
RangeValidatorto check whether the value is between -2147483647 and 1000.(In this particular case, it does seem like a single
RangeValidatorwith the message “Please enter a number between 0 and 1000” would result in less user frustration.)