3

In ASP.NET webforms, when setting UICulture="en" in the @Page directive, a Response.Write(Page.UICulture) returns the string "English" instead of the two letter language code "en".

Is the the only way to return the two letter language name by using this?

CultureInfo.CurrentUICulture.TwoLetterISOLanguageName

Or is there a better / more elegant way?

cHao
  • 84,970
  • 20
  • 145
  • 172
Alex Czarto
  • 3,151
  • 4
  • 28
  • 28

1 Answers1

3

Honestly I don't know of any better way to do it.

You could create an extension method, but that might be overkill:

public static class Extensions
{
    public static string GetUICultureCode(this System.Web.UI.Page page)
    {
        return System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
    }
}

Then in your page you can access it with this.GetUICultureCode()

Chris Mullins
  • 6,677
  • 2
  • 31
  • 40