Wednesday, May 21, 2008

Just few days ago, my friend at work found a peculiar error message in ASP.NET RangeValidator control. He was trying to validate length of a string in a TextBox. Controls on page definded as follows:

<asp:TextBox runat="server" ID="TB" />
<asp:RangeValidator runat="server" ID="RV" 
MinimumValue="3" MaximumValue="20" 
ControlToValidate="TB" Type="String" />

What he got was a best error message ever:

"The MaximumValue 20 cannot be less than the MinimumValue 3"

That's right! 20 cannot be less than 3!

Interesting isn't it?

I made some research of my own and I've found out that sane people should not look inside RaneValidator's (and other related classes) code! What it does inside is it uses a String.Compare to check if ranges are ok.

Of course, the problem are not the ranges, but the Type property of a validator. If set to String, it treates minimum and maximum values as strings and compares them as such - meaning that it compares character by character instead of just number to number.

That explains, why my friend got the error, but it certainly does not justify the text of the message! It might take long hours for an inexperienced developer to find where the problem lies. Come on Microsoft! You can do better than that!

Funny thing is that I never even thought about using RangeValidator to ensure string length, but suggested RegularExpressionValidator right from the start :-).

Wednesday, May 21, 2008 9:13:39 PM (Central European Standard Time, UTC+01:00)
heck it might take hours for any developer, this was still the developer fault
Wednesday, May 27, 2009 7:27:02 AM (Central European Standard Time, UTC+01:00)
fool give solution
ashish
Tuesday, December 08, 2009 10:02:58 AM (Central European Standard Time, UTC+01:00)
Hey. Liberals are very broadminded: they are always willing to give careful consideration to both sides of the same side.
I am from Israel and know bad English, give true I wrote the following sentence: "Casino royale, fisher referred to gain sure as it was his great depiction."

Waiting for a reply :D, Safford.
Tuesday, July 13, 2010 3:38:12 AM (Central European Standard Time, UTC+01:00)
Hello everybody, today really lucky
To introduce you these good online shops now!

Sale: GUCCI Bags, GUCCI Handbags, GUCCI Shoes, GUCCI Clothes, GUCCI Glasses, etc.
http://www.gucciboss.com/

2010 NFL, NFL Jerseys, NFL Jersey, NHL Jerseys, MLB Jerseys, NBA Jerseys, wholesale NFL Jerseys
http://www.2010-nfl.com/


Vibram,Five Fingers,fivefingers,Five Fingers Kso,Five Fingers Classic,Five Fingers Sprint,FiveFingers shoes,Vibram Outlet Sale
http://www.topfivefingers.com/

Christian Louboutin,Christian Louboutin shoes,Christian Louboutin sale,ChristianLouboutin Boots,Christian Louboutin Pumps,Christian Louboutin Sandals
http://www.superchristianlouboutin.com
Thursday, August 26, 2010 8:33:40 AM (Central European Standard Time, UTC+01:00)
http://www.gucciall.com
Discount Gucci, Discount Gucci Handbags, Gucci Sunglasses

http://www.wholesale-ugg-boots.com
UGG, UGG Boots, cheap UGG Boots

http://fivefingersshoes.tk
http://mychristianlouboutin.tk
http://ghdstraighteners.tk
http://kidsjerseys.tk
http://ghdshopping.tk
http://guccigucci.tk
http://saleshoes.tk
http://thehandbags.tk


http://ilikehandbags.tk
http://ilikejerseys.tk
http://isshoes.tk
http://rarehandbags.tk
http://rarejerseys.tk
http://rareshoes.tk
http://sellhandbags.tk
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview