Solved

ASP.NET VALIDATION

Posted on 2003-12-08
20
1,307 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grunt No Clean Targets 6 108
site launch date and last modified date 3 80
Compare site how does it work 4 71
reset email that plugins send alerts to 1 35
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now