13 Ağustos 2010 Cuma

C# Multi-language web page with cookie

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){
   HttpCookie cookie = new HttpCookie("DropDownName");
   cookie.Value=DropDownList1.UniqueID;
   Response.SetCookie(cookie);
}

in global asax
void Application_BeginRequest(Object sender, EventArgs e){
      string lang = string.Empty;
//default to the invariant culture      HttpCookie cookie = Request.Cookies["DropDownName"];
      if (cookie != null && cookie.Value != null)
         lang = Request.Form[cookie.Value];
      Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);
      Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
}

Hiç yorum yok:

Yorum Gönder