Link to home
Start Free TrialLog in
Avatar of smaill
smaill

asked on

ASP.NET VALIDATION

Hello I am using a range validator, and getting this error message


System.Web.HttpException: The MaximumValue £10,339.58 cannot be less than the MinimumValue £10.00 of RV_amounttxtbx.

Is it not possible for the validator to accept culture in the comparison?

Avatar of smaill
smaill

ASKER

How do I view responses?
Avatar of YZlat
how did you enter the naximum value? 10,339.58 or 10339.58?
post your code, so we could look at it and figure out the problem
did you set the type to "currency"?
Avatar of smaill

ASKER



I use some code to determine amount max and min, then plug it into the range amounts, both amountmax and amountmin are decimal.

RV_amounttxtbx.maximumvalue = amountmax.tostring("C")
RV_amounttxtbx.minimumvalue = amountmin.tostring("C")

The body has
<asp:rangevalidator ID="RV_amounttxtbx" EnableClientScript="false" ControlToValidate="amount1txtbx" Display="Dynamic" runat="server"/>

try this

<asp:rangevalidator ID="RV_amounttxtbx"
EnableClientScript="false"
ErrorMessage="Please enter a number between 10.00 and 10,339.58" ControlToValidate="amount1txtbx"
Type="Currency"
Display="Dynamic"
runat="server"/>

also try changing

RV_amounttxtbx.maximumvalue = amountmax.tostring("C")
RV_amounttxtbx.minimumvalue = amountmin.tostring("C")

to

RV_amounttxtbx.maximumvalue = 10.00
RV_amounttxtbx.minimumvalue = 10,339.85

toString() could cause the problem as well
Avatar of smaill

ASKER

I entered 'Type="Currency" '

I define the error message here.

If amountmax < 10 then
      amounterrormessage = "Deposits of less than 10 pounds will not be accepted"
Else
      amounterrormessage = "Please enter an amount between " & amountmin.tostring("C") & " and " & amountmax.tostring("C") & " With pound sign."
End If      
RV_amounttxtbx.errormessage = amounterrormessage

I get the following error message

The value '£10,339.58' of the MaximumValue property of 'RV_amounttxtbx' cannot be converted to type 'Currency'.

this amount is comes from the textbox

<asp:textbox ID="amount1txtbx" runat="server" Width="80"/>
(defaults to maxvalue)

So I removed the .tostring("C") from:

RV_amounttxtbx.maximumvalue = amountmax.tostring("C")
RV_amounttxtbx.minimumvalue = amountmin.tostring("C")

Then the validation works (ish) as then i get the 'Else' condition outlined above.
Avatar of smaill

ASKER

I cannot change to a fixed value as this is driven through SQL and is dependant on who is logged in, and the max amount they can deposit.
Avatar of smaill

ASKER

Sorry, I should have mentioned this earlier. It never has a problem under £1,000 pounds, maybe because of the comma?
Avatar of smaill

ASKER

Again, after a little investigating, amountmax is already inherently set to currency as i get it from another string.

Is there a way to convert from type currency to type decimal? I believe this would fix my problem
you can convert currency to decimal the following way:

amount = Convert.ToDecimal (amount1txtbx.Text)

but I think the problem is caused by the £ sign
also change your if statement from

If amountmax < 10 then
     amounterrormessage = "Deposits of less than 10 pounds will not be accepted"
Else
     amounterrormessage = "Please enter an amount between " & amountmin.tostring("C") & " and " & amountmax.tostring("C") & " With pound sign."
End If    


to something like that:

If amountmax < 10 then
     amounterrormessage = "Deposits of less than 10 pounds will not be accepted"
Elseif amountmax > 10000
     amounterrormessage = "Deposits of more than 10,000 pounds will not be accepted"
Else
     amounterrormessage = "Please enter an amount between " & amountmin.tostring("C") & " and " & amountmax.tostring("C") & " With pound sign."
End If    

This way your validation takes care of the maximum amount of 10,000 as well and does not give you error message every time the amount exceeds 10.00
I'm sorry. made a mistake, change your if statement to

If amountmax < 10 then
     amounterrormessage = "Deposits of less than 10 pounds will not be accepted"
Elseif amountmax > 10000
     amounterrormessage = "Deposits of more than 10,000 pounds will not be accepted"
End If    

so that the user can enter a maximum amount between 10.00 and 10,000.00 pounds    

Avatar of smaill

ASKER

Ok, I still get the 'else' condition occuring.

Also, it no longer works for amounts under £1,000 pounds.

Just to refresh, here is the code that I am now using.

RV_amounttxtbx.errormessage = amounterrormessage
RV_amounttxtbx.maximumvalue = Convert.ToDecimal(amountmax)
RV_amounttxtbx.minimumvalue = amountmin


<asp:rangevalidator ID="RV_amounttxtbx"
Type="Currency"
EnableClientScript="false"
ControlToValidate="amount1txtbx"
Display="Dynamic"
runat="server"/>
what 'else' condition?
Avatar of smaill

ASKER

I missed one your comments, so I will address that first.

You suggested:
If amountmax < 10 then
     amounterrormessage = "Deposits of less than 10 pounds will not be accepted"
Elseif amountmax > 10000
     amounterrormessage = "Deposits of more than 10,000 pounds will not be accepted"
End If    

so that the user can enter a maximum amount between 10.00 and 10,000.00 pounds

The minimum value is hardcoded to £10. The maximum value is the result of a query, this is not necessarily £10,000 it may be £100, so the max value cannot be static.

Secondly,

I get the else condition from above:

Else
     amounterrormessage = "Please enter an amount between " & amountmin.tostring("C") & " and " & amountmax.tostring("C") & " With pound sign."
End If
ASKER CERTIFIED SOLUTION
Avatar of bacchus5150
bacchus5150

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the if statement takes care of the values below 10000, which includes 100 or any amount above 10.00 and below 10,000. It is not static
just post all your code and I'll test it on my machine