Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > RangeFieldValidator in ASP.NET 1.1

Reply
Thread Tools

RangeFieldValidator in ASP.NET 1.1

 
 
Hardy Wang
Guest
Posts: n/a
 
      05-11-2006
Hi, I have a RangeFieldValidator in my Web Form to validate input of
monetary. I set current thread's culture to "FR-CA", and I tried following
ways

valCost.MaximumValue = (99999.99).ToString("N2");
I get run time error "The value '99 999,99' of the MaximumValue property of
'valCost' cannot be converted to type 'Currency'."

valCost.MaximumValue = (99999.99).ToString("C");
I get run time error "The value '99 999,99 $' of the MaximumValue property
of 'valCost' cannot be converted to type 'Currency'."

valCost.MaximumValue = "99999.99";
I get run time error "The value '99999.99' of the MaximumValue property of
'valCost' cannot be converted to type 'Currency'."

Since this is a web application which supports multiple languages at
run-time (users can select a language as they wish), how can I dynamically
set the max value to the validator to support all languages?

Thanks for any syggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-12-2006
Hi Hardy,

Thank you for posting.

As for the ASP.NET 1.x RangeValidator control's currency validating
problem, based on my research, here are some of my understanding and
suggestion:

The RangeValidator's Validation on String or Currency does support
different Culture(globalize) scenario. And actually, the code logic is:

1. The validator control will first retrieve the string value from the
validated target control and the Min , Max property, then convert them to
the certain DAta Type. If its currency value, it will convert it from
culture specific value into Culture Netural value.

2. After #1, then perform comparing on the converted value.

So as for the MaximumValue and MinimumValue, it does support localized
value. However, we can not add the currency sign (such as $, € ....) into
it. So we should use the "N" flag when formating the decimal value. Here is
the test page I used to dynamically set the RangValidator's range
properties according to the runtime thread culture:



========================
private void Page_Load(object sender, System.EventArgs e)
{
CultureInfo ci = new CultureInfo("de-DE");
Thread.CurrentThread.CurrentCulture = ci;

decimal dv1 = 222434.4343M;
decimal dv2 = 444434.4343M;

rv.MinimumValue = dv1.ToString("N2",
Thread.CurrentThread.CurrentCulture);
rv.MaximumValue = dv2.ToString("N2",
Thread.CurrentThread.CurrentCulture);


Response.Write(
string.Format("<br/>dv1: {0:N2}, dv2: {1:N2}", dv1, dv2)
);

}

===================================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments