Use Profile object to store a user's preferred culture : CultureInfo « I18N « ASP.NET Tutorial

Home
ASP.NET Tutorial
1.ASP.Net Instroduction
2.Language Basics
3.ASP.net Controls
4.HTML Controls
5.Page Lifecycle
6.Response
7.Collections
8.Validation
9.Development
10.File Directory
11.Sessions
12.Cookie
13.Cache
14.Custom Controls
15.Profile
16.Configuration
17.LINQ
18.ADO.net Database
19.Data Binding
20.Ajax
21.Authentication Authorization
22.I18N
23.Mobile
24.WebPart
25.XML
ASP.NET Tutorial » I18N » CultureInfo 




<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">

    protected override void InitializeCulture()
    {
        Culture = Profile.UserCulture;
        UICulture = Profile.UserUICulture;
    }
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        Profile.UserCulture = ddlCulture.SelectedValue;
        Profile.UserUICulture = ddlCulture.SelectedValue;
        Response.Redirect(Request.Path);
    }

    void Page_PreRender()
    {
        lblDate.Text = DateTime.Now.ToString("D");
        lblPrice.Text = (512.33m).ToString("c");
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Select Culture Profile</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblCulture"
        Text="Culture:"
        AssociatedControlID="ddlCulture"
        Runat="server" />

    <asp:DropDownList
        id="ddlCulture"
        DataTextField="DisplayName"
        DataValueField="Name"
        DataSourceID="srcCultures"
        Runat="server" />

    <asp:Button
        id="btnSelect"
        Text="Select"
        Runat="server" OnClick="btnSelect_Click" />


    <asp:ObjectDataSource
        id="srcCultures"
        TypeName="System.Globalization.CultureInfo"
        SelectMethod="GetCultures"
        Runat="server">
        <SelectParameters>
            <asp:Parameter Name="types" DefaultValue="SpecificCultures" />
        </SelectParameters>
    </asp:ObjectDataSource>

    <hr />

    Today's date is:
    <br />
    <asp:Label
        id="lblDate"
        Runat="server" />

    <br /><br />

    The price of the product is:
    <br />
    <asp:Label
        id="lblPrice"
        Runat="server" />

    </div>
    </form>
</body>
</html>

File: Web.Config

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
    <anonymousIdentification enabled="true"/>
    <profile>
      <properties>
        <add
          name="UserCulture"
          defaultValue="en-US" />
        <add
          name="UserUICulture"
          defaultValue="en"/>
      </properties>
    </profile>
  </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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.