Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

CompareValidator + RangeValidator not working together

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
Rouchie
Asked:
Rouchie
1 Solution
 
ethothsCommented:
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
 
RouchieAuthor Commented:
Ah, so I'm not mad (well, not entirely!).  

Thanks ethoths
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now