Calendar Localisation

N

Newsgroup Post

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!
 
K

Ken Cox [Microsoft MVP]

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>


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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top