How to change the UICulture in an ASP.NET Page

Published 26/6/2008 20:56 | Eugenio Estrada

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/

Archivado en:
Comparte este post:

Comentarios

# Gabo.Net said on June 27, 2008 1:44 AM:

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

# Eugenio Estrada said on June 27, 2008 9:53 AM:

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!

# José M. Alarcón Aguín said on June 28, 2008 12:17 PM:

Hola Euge:

Te dejo algunas aportaciones más a este post en uno mío que publiqué hace ya algún tiempo:

www.jasoft.org/.../PermaLink,guid,659bc8a5-5f82-43c9-9379-8127b4e90bd7.aspx

Saludos

JM

# Jaime said on July 8, 2008 6:42 PM:

Porque no en el evento load (está en VB):

Imports System.Globalization

Imports System.Threading

.....

....

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