Solved

CompareValidator + RangeValidator not working together

Posted on 2006-11-07
2
434 Views
Last Modified: 2008-06-17
I must be doing something really stupid here but I can't get the following logic to work.  I need the user to enter a numeric (double) figure into the textbox that is between 0 - 250.

So:
   "abc" is not valid
   0 is valid
   53.535 is valid
   250 is valid
   251 is not valid

The page code is as follows:

<asp:TextBox ID="txt_higher" runat="server" />
<asp:CompareValidator ID="cmpval1" runat="server" ControlToValidate="txt_higher" Operator="dataTypeCheck" Type="double" ValidationGroup="vg1" Text="Value in box 1 must be numeric." />
<asp:RangeValidator ID="rngval1" runat="server" ControlToValidate="txt_higher" MaximumValue="250" MinimumValue="0" Text="Value in box 1 must be 0-250." ValidationGroup="vg1" />
<br />
<br />
<asp:Button ID="btn" runat="server" Text="Validate" ValidationGroup="vg1" CausesValidation="true"  />

However if I enter 50 into the box, the page won't validate.  ASP.NET 2.0 seems to think that 50 does not lie between 0-250.  Am I going mad?
0
Comment
Question by:Rouchie
2 Comments
 
LVL 11

Accepted Solution

by:
ethoths earned 500 total points
ID: 17888895
It's doing a text compare. You need to tell it the type...


<asp:RangeValidator type="Double" ID="rngval1" runat="server" ControlToValidate="txt_higher" MaximumValue="250" MinimumValue="0" Text="Value in box 1 must be 0-250." ValidationGroup="vg1" />
0
 
LVL 25

Author Comment

by:Rouchie
ID: 17889212
Ah, so I'm not mad (well, not entirely!).  

Thanks ethoths
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASCX file or a newer alternative? 1 35
Syntax Error 2 64
ASP.net File format issue in producing Excel file 3 37
ASP.NET MVC identity 6 26
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question