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?
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?
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"?
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.maximumvalu
RV_amounttxtbx.minimumvalu
The body has
<asp:rangevalidator ID="RV_amounttxtbx" EnableClientScript="false"
try this
<asp:rangevalidator ID="RV_amounttxtbx"
EnableClientScript="false"
ErrorMessage="Please enter a number between 10.00 and 10,339.58" ControlToValidate="amount1
Type="Currency"
Display="Dynamic"
runat="server"/>
also try changing
RV_amounttxtbx.maximumvalu e = amountmax.tostring("C")
RV_amounttxtbx.minimumvalu e = amountmin.tostring("C")
to
RV_amounttxtbx.maximumvalu e = 10.00
RV_amounttxtbx.minimumvalu e = 10,339.85
toString() could cause the problem as well
RV_amounttxtbx.maximumvalu
RV_amounttxtbx.minimumvalu
to
RV_amounttxtbx.maximumvalu
RV_amounttxtbx.minimumvalu
toString() could cause the problem as well
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.errormessag e = 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.maximumvalu e = amountmax.tostring("C")
RV_amounttxtbx.minimumvalu e = amountmin.tostring("C")
Then the validation works (ish) as then i get the 'Else' condition outlined above.
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.errormessag
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.maximumvalu
RV_amounttxtbx.minimumvalu
Then the validation works (ish) as then i get the 'Else' condition outlined above.
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.
ASKER
Sorry, I should have mentioned this earlier. It never has a problem under £1,000 pounds, maybe because of the comma?
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
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
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
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
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
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.errormessag e = amounterrormessage
RV_amounttxtbx.maximumvalu e = Convert.ToDecimal(amountma x)
RV_amounttxtbx.minimumvalu e = amountmin
<asp:rangevalidator ID="RV_amounttxtbx"
Type="Currency"
EnableClientScript="false"
ControlToValidate="amount1 txtbx"
Display="Dynamic"
runat="server"/>
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.errormessag
RV_amounttxtbx.maximumvalu
RV_amounttxtbx.minimumvalu
<asp:rangevalidator ID="RV_amounttxtbx"
Type="Currency"
EnableClientScript="false"
ControlToValidate="amount1
Display="Dynamic"
runat="server"/>
what 'else' condition?
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ASKER