Solved

ASP.NET VALIDATION

Posted on 2003-12-08
20
1,306 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
  • 11
  • 8
20 Comments
 

Author Comment

by:smaill
Comment Utility
How do I view responses?
0
 
LVL 35

Expert Comment

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

Expert Comment

by:YZlat
Comment Utility
post your code, so we could look at it and figure out the problem
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
did you set the type to "currency"?
0
 

Author Comment

by:smaill
Comment Utility


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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, I should have mentioned this earlier. It never has a problem under £1,000 pounds, maybe because of the comma?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:smaill
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
what 'else' condition?
0
 

Author Comment

by:smaill
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
just post all your code and I'll test it on my machine
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now