Question : 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?

Answer : ASP.NET VALIDATION

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
Random Solutions  
 
programming4us programming4us