views:

292

answers:

1

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?

+1  A: 

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