locked
Enterprise Library Validator 3.1 and culture codes RRS feed

  • Question

  • User-319553221 posted

    I'm having a bit of trouble mixing culture codes and the enterprise library 3.1 validator application block.

    I have a page that is using cultures to select from a list of resource files which return a message in their language to the user.

      public virtual ValidationResults Validate(string ruleSet, string languageCode)
    {
    Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageCode);

    Validator<Contact> validator = ValidationFactory.CreateValidator<Contact>(ruleSet);
    ValidationResults results = validator.Validate(this);

    return results;
    }


    The first time the page runs, the user fills out some forms, and the page will return the correct error message from the .resx using the pages language code. The problem is that it only works the first time round. When I submit the form a second time using a different culture code, the validator still uses the old culture code. Unless I restart the server the culture code refuses to update.

    The code seems simple enough, but it just keeps getting stuck on the first culture code I change to. The threads do seem to be getting set to the new cultures, and the correct language codes do seem to be getting passed, but when the validator returns "results" in the last line it's always the first culture.


    Anyone have any ideas?

    Wednesday, February 3, 2010 10:59 AM

All replies

  • User-319553221 posted

    not sure if that code got truncated or it's just my browser, but here it is again just in case:


    public virtual ValidationResults Validate(string ruleSet, string languageCode)
            {
                

                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageCode);

                Validator<Contact> validator = ValidationFactory.CreateValidator<Contact>(ruleSet);
                ValidationResults results = validator.Validate(this);

                return results;
            }

    Wednesday, February 3, 2010 3:01 PM