Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Calendar Localisation

Reply
Thread Tools

Calendar Localisation

 
 
Newsgroup Post
Guest
Posts: n/a
 
      08-03-2003
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!


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      08-09-2003
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" <(E-Mail Removed)> wrote in message
news:3f2cfb75$0$223$(E-Mail Removed)...
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!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 2.0 Localisation problem Localizable attribute not working... aidancasey@gmail.com ASP .Net 2 09-19-2007 12:41 PM
Localisation query BabuLives ASP .Net 1 11-09-2005 12:32 PM
[Newbie UK Date problem] Ways atround this UK date format localisation/SQLselection issue? DC ASP .Net 5 07-01-2005 09:35 PM
Localisation problem Olivier Matrot ASP .Net 1 03-08-2005 11:24 AM
Localisation Toolkit and Repeater controls Tony ASP .Net 1 02-10-2004 01:07 PM



Advertisments