Choose culture control : CultureInfo « I18N « ASP.NET Tutorial






<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Control.ascx.cs" Inherits="ChooseCultureControl" %>

<div id="cultureStyle">   
   <asp:Localize ID="locCountry" runat="server" meta:resourcekey="locCountry1" Text="Country :" ></asp:Localize>
   <asp:ImageButton ID="imgUS" runat="server"
     CssClass="cultureFlag" BorderWidth="1" 
     CommandName="US"
     OnCommand="imgCommand"
     ImageUrl="images/flag_us.gif"
     meta:resourcekey="imgUSResource1"   />
   <asp:ImageButton ID="imgFR" runat="server"
     CssClass="cultureFlag" BorderWidth="1" 
     CommandName="France" 
     OnCommand="imgCommand"
     ImageUrl="images/flag_fr.gif"
     meta:resourcekey="imgFRResource1" />
</div>

File: Control.ascx.cs
 

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChooseCultureControl : System.Web.UI.UserControl
{
   protected void Page_Load(object sender, EventArgs e)
   {

      if (Profile.Culture == "fr-FR")
      {
         imgFR.BorderStyle = BorderStyle.Dotted;
         imgUS.BorderStyle = BorderStyle.None;
      }
      else
      {
         imgUS.BorderStyle = BorderStyle.Dotted;
         imgFR.BorderStyle = BorderStyle.None;
      }
   }

   protected void imgCommand(object sender, CommandEventArgs e)
   {

      if (e.CommandName == "France")
         Profile.Culture = "fr-FR";
      else
         Profile.Culture = "en-US";


      Response.Redirect(Request.Url.AbsolutePath);
   }
}


File: Web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <anonymousIdentification enabled="true"/>
    <profile>
      <properties>
        <add name="Culture" type="string" allowAnonymous="true" defaultValue="auto"/>
      </properties>
    </profile>
    <compilation debug="true"/>
   </system.web>
</configuration>








22.1.CultureInfo
22.1.1.Create CultureInfo
22.1.2.Selecting a culture from a DropDownList control.
22.1.3.Use Profile object to store a user's preferred culture
22.1.4.Using the CultureInfo Class to Format String Values
22.1.5.Select CultureAuto
22.1.6.Choose culture control