How to change the UICulture in an ASP.NET Page

Sometimes, we’d stored a cookie with the user language preference. But, the fact of change the Page.UICulture don’t have any resoult.

To changed this property we should do it inside the InitializeCulture Page method and override it. Imagine that the cookie is called “lang”:

protected override void InitializeCulture()

{

    if (Request.Cookies["lang"] != null)

    {

        if (Request.Cookies["lang"].Value != "")

        {

            Page.UICulture = Request.Cookies["lang"].Value;

        }

    }

    base.InitializeCulture();

}

Thus, you could change the page language ;).

http://eugenioestrada.es/blog/

4 thoughts on “How to change the UICulture in an ASP.NET Page

  1. También pudo ser con String.IsNullOrEmpty ¿?. Habrá diferencias en rendimiento? jejeje si lo hubieran serían ínfimos o casi nulos seguros jejeje.

    protected override void InitializeCulture()
    {
    if(!String.IsNullOrEmpty(Request.Cookies[«lang»].Value))
    Page.UICulture = Request.Cookies[«lang»].Value;
    base.InitializeCulture();
    }

    Buen post!
    Saludos

  2. Gracias por tu respuesta!

    No había pensado en eso, pero me imagino que si que habrá mejoras de rendimiento pero habría que mirar el código interno para comprobarlo.

    Cuando pueda le echo un ojo y comento 🙂

    Un saludo!

  3. Porque no en el evento load (está en VB):
    Imports System.Globalization
    Imports System.Threading
    …..
    ….

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(«es-PE»)

Responder a anonymous Cancelar respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *