Imports System.Globalization
Imports BasicFrame.WebControls
Public Class Sample6
Inherits System.Web.UI.Page
Dim requestCulture As CultureInfo
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
' Wrapped in try/catch because some user agents(browsers)
' do not send out UserLanguage options. If no UserLanguage in HttpHeaders,
' then .CreateSpecificCulture() will throw an exception.
Try
' Request top UserLanguage from user agent and create CultureInfo object.
requestCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0))
Catch
' Return server Culture if none available in HttpHeaders.
requestCulture = CultureInfo.CurrentCulture
End Try
Me.BasicDatePicker1.SelectedDate = DateTime.Today
' set BDP DateFormat to display Culture dependent ShortDate pattern
BasicDatePicker1.DateFormat = DateFormat.ShortDate
' print out User Agent Culture.
Label2.Text = "Your browser Culture: <blockquote><strong>" + requestCulture.DisplayName + "</strong></blockquote>"
Label3.Text = "Current BasicDatePicker Culture: <blockquote><strong>" + requestCulture.DisplayName + "</strong></blockquote>"
BindCultureList()
End If
End Sub
Private Sub BindCultureList()
' Get all Cultures from the .NET Framework
Me.ddlCultures.DataSource = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
Me.ddlCultures.DataValueField = "Name"
Me.ddlCultures.DataTextField = "DisplayName"
Me.ddlCultures.DataBind()
BasicDatePicker1.Culture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0))
' Loop through all the Cultures in the DropDownList and select the current culture.
Dim item As ListItem
For Each item In ddlCultures.Items
If item.Value = requestCulture.Name Then
item.Selected = True
Else
item.Selected = False
End If
Next
End Sub
Public Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
' Create a Culture object from the item selected in the DropDownlList.
Dim culture As CultureInfo = New CultureInfo(ddlCultures.SelectedValue)
Me.BasicDatePicker1.Culture = culture
Label1.Text = "You picked: <strong>" + BasicDatePicker1.SelectedDateFormatted + "</strong>"
Label3.Text = "Current BasicDatePicker Culture : <blockquote><strong>" + culture.DisplayName + "</strong></blockquote>"
Label4.Text = "Current ShortDate pattern: <strong>" + culture.DateTimeFormat.ShortDatePattern + "</strong>"
End Sub
Private Sub BasicDatePicker1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BasicDatePicker1.SelectionChanged
Label1.Text = "You picked: <strong>" + BasicDatePicker1.SelectedDateFormatted + "</strong>"
Label4.Text = "Current ShortDate pattern: <strong>" + System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern + "</strong>"
End Sub
#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 Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents BasicDatePicker1 As BasicFrame.WebControls.BasicDatePicker
Protected WithEvents ddlCultures As System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
'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
End Class