Solved

ASP.NET VALIDATION

Posted on 2003-12-08
20
1,311 Views
Last Modified: 2012-05-04
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?

0
Comment
Question by:smaill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
20 Comments
 

Author Comment

by:smaill
ID: 9896993
How do I view responses?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9897565
how did you enter the naximum value? 10,339.58 or 10339.58?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9897569
post your code, so we could look at it and figure out the problem
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 35

Expert Comment

by:YZlat
ID: 9897620
did you set the type to "currency"?
0
 

Author Comment

by:smaill
ID: 9897708


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"/>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9897750

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"/>

0
 
LVL 35

Expert Comment

by:YZlat
ID: 9897866
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
0
 

Author Comment

by:smaill
ID: 9897887
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.
0
 

Author Comment

by:smaill
ID: 9897925
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.
0
 

Author Comment

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

Author Comment

by:smaill
ID: 9897983
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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9898110
you can convert currency to decimal the following way:

amount = Convert.ToDecimal (amount1txtbx.Text)

but I think the problem is caused by the £ sign
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9898153
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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9898169
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    

0
 

Author Comment

by:smaill
ID: 9898214
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"/>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9898240
what 'else' condition?
0
 

Author Comment

by:smaill
ID: 9898310
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
0
 
LVL 1

Accepted Solution

by:
bacchus5150 earned 500 total points
ID: 9898403
Well, I would suggest:

  There is a problem with the .ToString("C") problem
  You have 2 different number formats to begin with, 10.00 and 10,339.58

When you are dealing with the validator, I would make sure that the max and min values are the same format, IE decimal xxx.xx and yyy.yy.  Just set these decimal values to the validator and it should be happy.  When you set the min/max with .ToString("C") it is actually trying to set "$10.00" as the value, not 10.00

As for the display, you asked about displaying the value based on culture.  Look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemGlobalizationNumberFormatInfoClassTopic.asp

It explains how you can create a new culture, and then format your information based on that culture, IE:

        Dim ciNewCultureInfo As New System.Globalization.CultureInfo("en-GB", False)
        Dim nfiNewNumberFormatInfo As New System.Globalization.NumberFormatInfo()


        nfiNewNumberFormatInfo = ciNewCultureInfo.NumberFormat

You now have access to all of the important information you need to format your values, such as:
    nfiNewNumberFormatInfo.CurrencyGroupSeparator
    nfiNewNumberFormatInfo.CurrencySymbol

Now you can format your string based on whatever culture you want.  I did not look into using the culture object to format your values, but it should(hopefully) be not too difficult.

Hope this helps
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9898415
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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9898424
just post all your code and I'll test it on my machine
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Suggested Solutions

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

752 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