Use namespace
- System.Threading
- System.Globalization
<p>
<asp:dropdownlist id='DropDownlist1' runat='server'></asp:dropdownlist></p>
<p>
<asp:Button id='Button1' runat='server' Text='Button'></asp:Button></p>
<asp:calendar id='Calendar1' runat='server'></asp:calendar>
VB.NET
Dim userLang() As String
Dim strLang As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
’Put user code to initialize the page here
userLang = Request.UserLanguages
ViewState('userLanguage') = userLang(userLang.GetUpperBound(0))
If ViewState('userLanguage') = '' Then
ViewState('userLanguage') = 'en-US'
End If
Dim ci As CultureInfo
For Each ci In CultureInfo.GetCultures(CultureTypes.AllCultures)
If Not ci.IsNeutralCulture Then
DropDownlist1.Items.Add(ci.ToString)
End If
Next
Dim dtNow As Date = DateTime.Now
strLang = ViewState('userLanguage')
Thread.CurrentThread.CurrentUICulture = New CultureInfo(strLang, False)
Thread.CurrentThread.CurrentCulture = New CultureInfo(strLang)
Calendar1.SelectedDate = dtNow
Calendar1.VisibleDate = dtNow
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
strLang = ViewState('userLanguage')
Thread.CurrentThread.CurrentUICulture = New CultureInfo(strLang, False)
Thread.CurrentThread.CurrentCulture = New CultureInfo(strLang)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
strLang = DropDownlist1.SelectedItem.Text
ViewState('userLanguage') = strLang
Thread.CurrentThread.CurrentUICulture = New CultureInfo(strLang, False)
Thread.CurrentThread.CurrentCulture = New CultureInfo(strLang)
End Sub
C#
string[] userLang;
string strLang;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
userLang = Request.UserLanguages;
ViewState['userLanguage'] = userLang[userLang.GetUpperBound(0)];
if( ViewState['userLanguage'].ToString () == '' )
{
ViewState['userLanguage'] = 'en-US';
}
foreach(CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
if(!ci.IsNeutralCulture)
{
DropDownlist1.Items.Add(ci.ToString());
}
}
DateTime dtNow = DateTime.Now;
strLang =(string) ViewState['userLanguage'];
Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLang, false);
Thread.CurrentThread.CurrentCulture =new CultureInfo(strLang);
Calendar1.SelectedDate = dtNow;
Calendar1.VisibleDate = dtNow;
}
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
strLang =(string) ViewState['userLanguage'].ToString ();
Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLang, false);
Thread.CurrentThread.CurrentCulture = new CultureInfo(strLang);
}
private void Button1_Click(object sender, System.EventArgs e)
{
strLang = DropDownlist1.SelectedItem.Text;
ViewState['userLanguage'] = strLang;
Thread.CurrentThread.CurrentUICulture =new CultureInfo(strLang, false);
Thread.CurrentThread.CurrentCulture = new CultureInfo(strLang);
}
Share with