RangeFieldValidator in ASP.NET 1.1

Discussion in 'ASP .Net' started by Hardy Wang, May 11, 2006.

  1. Hardy Wang

    Hardy Wang Guest

    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
     
    Hardy Wang, May 11, 2006
    #1
    1. Advertising

  2. 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.)
     
    Steven Cheng[MSFT], May 12, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Elmhorst
    Replies:
    2
    Views:
    514
    Bassel Tabbara [MSFT]
    Jul 8, 2003
  2. dave
    Replies:
    0
    Views:
    1,297
  3. Ben
    Replies:
    3
    Views:
    1,187
  4. Andrea Raimondi
    Replies:
    1
    Views:
    508
  5. Amelyan
    Replies:
    2
    Views:
    175
    Amelyan
    Apr 25, 2005
Loading...

Share This Page