Solved

ASP.NET VALIDATION

Posted on 2003-12-08
20
1,309 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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.

827 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