Calendar Localisation

Discussion in 'ASP .Net Web Controls' started by Newsgroup Post, Aug 3, 2003.

  1. Hi,
    I'd like to make my Asp.Net components (such as the calendar control)
    appear in the language of the machine that the user is using. What's the
    best way to do this?

    Thanks in advance!
     
    Newsgroup Post, Aug 3, 2003
    #1
    1. Advertising

  2. Here's a little sample code I was playing with to look at the calendar control
    in various cultures. As you can see, you can detect the culture from the
    browser or let the user choose the culture.

    Does this help?

    Ken
    MVP [ASP.NET]

    Imports System.Globalization
    Imports System.Threading

    Public Class callocal
    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Calendar1 As _
    System.Web.UI.WebControls.Calendar
    Protected WithEvents Label1 As _
    System.Web.UI.WebControls.Label
    Protected WithEvents btnTry As _
    System.Web.UI.WebControls.Button
    Protected WithEvents ddlCultures As _
    System.Web.UI.WebControls.DropDownList

    'NOTE: The following placeholder declaration
    ' is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region


    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load

    If Not IsPostBack Then
    Dim ci As CultureInfo
    For Each ci In _
    CultureInfo.GetCultures(CultureTypes.AllCultures)
    If Not ci.IsNeutralCulture Then
    ddlCultures.Items.Add(ci.ToString)
    End If
    Next ci
    If Request.UserLanguages.Length <> 0 Then
    Session("strLanguage") = Request.UserLanguages(0)
    Else
    Session("strLanguage") = "en-US"
    End If
    Dim dtNow As Date = DateTime.Now
    Dim strName As String = Session("strLanguage")
    Thread.CurrentThread.CurrentUICulture = _
    New CultureInfo(strName, False)
    Thread.CurrentThread.CurrentCulture = _
    New CultureInfo(strName)
    Calendar1.SelectedDate = dtNow
    Calendar1.VisibleDate = dtNow
    End If
    End Sub


    Private Sub Calendar1_SelectionChanged _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles Calendar1.SelectionChanged
    Dim strName As String = Session("strLanguage")
    Thread.CurrentThread.CurrentUICulture = _
    New CultureInfo(strName, False)
    Thread.CurrentThread.CurrentCulture = _
    New CultureInfo(strName)
    End Sub

    Private Sub btnTry_Click _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnTry.Click
    Dim strName As String
    strName = ddlCultures.SelectedItem.Text
    Session("strLanguage") = strName
    Thread.CurrentThread.CurrentUICulture = _
    New CultureInfo(strName, False)
    Thread.CurrentThread.CurrentCulture = _
    New CultureInfo(strName)
    End Sub
    End Class

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="callocal.aspx.vb"
    Inherits="p733workev.callocal"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>callocal</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    </head>
    <body ms_positioning="FlowLayout">
    <form id="Form1" method="post" runat="server">
    <p>
    <asp:dropdownlist id="ddlCultures"
    runat="server"></asp:dropdownlist></p>
    <p>
    <asp:button id="btnTry" runat="server" text="Try It!"></asp:button></p>
    <asp:calendar id="Calendar1" runat="server"></asp:calendar>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </form>
    </body>
    </html>


    "Newsgroup Post" <> wrote in message
    news:3f2cfb75$0$223$...
    Hi,
    I'd like to make my Asp.Net components (such as the calendar control)
    appear in the language of the machine that the user is using. What's the
    best way to do this?

    Thanks in advance!
     
    Ken Cox [Microsoft MVP], Aug 9, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony
    Replies:
    1
    Views:
    386
    .NET Follower
    Feb 10, 2004
  2. Olivier Matrot

    Localisation problem

    Olivier Matrot, Mar 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    457
    Olivier Matrot
    Mar 8, 2005
  3. DC
    Replies:
    5
    Views:
    3,009
    Brendan Reynolds
    Jul 1, 2005
  4. BabuLives

    Localisation query

    BabuLives, Nov 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    339
    Karl Seguin
    Nov 9, 2005
  5. Replies:
    2
    Views:
    3,400
    Abdoosh
    Sep 19, 2007
Loading...

Share This Page