Pick a Date:
Culture: Arabic (Saudi Arabia) Bulgarian (Bulgaria) Catalan (Catalan) Chinese (Taiwan) Czech (Czech Republic) Danish (Denmark) German (Germany) Greek (Greece) English (United States) Finnish (Finland) French (France) Hebrew (Israel) Hungarian (Hungary) Icelandic (Iceland) Italian (Italy) Japanese (Japan) Korean (Korea) Dutch (Netherlands) Norwegian, Bokmål (Norway) Polish (Poland) Portuguese (Brazil) Romanian (Romania) Russian (Russia) Croatian (Croatia) Slovak (Slovakia) Albanian (Albania) Swedish (Sweden) Thai (Thailand) Turkish (Turkey) Urdu (Islamic Republic of Pakistan) Indonesian (Indonesia) Ukrainian (Ukraine) Belarusian (Belarus) Slovenian (Slovenia) Estonian (Estonia) Latvian (Latvia) Lithuanian (Lithuania) Persian (Iran) Vietnamese (Vietnam) Armenian (Armenia) Azeri (Latin, Azerbaijan) Basque (Basque) Macedonian (Former Yugoslav Republic of Macedonia) Afrikaans (South Africa) Georgian (Georgia) Faroese (Faroe Islands) Hindi (India) Malay (Malaysia) Kazakh (Kazakhstan) Kyrgyz (Kyrgyzstan) Kiswahili (Kenya) Uzbek (Latin, Uzbekistan) Tatar (Russia) Punjabi (India) Gujarati (India) Tamil (India) Telugu (India) Kannada (India) Marathi (India) Sanskrit (India) Mongolian (Cyrillic, Mongolia) Galician (Galician) Konkani (India) Syriac (Syria) Divehi (Maldives) Arabic (Iraq) Chinese (People's Republic of China) German (Switzerland) English (United Kingdom) Spanish (Mexico) French (Belgium) Italian (Switzerland) Dutch (Belgium) Norwegian, Nynorsk (Norway) Portuguese (Portugal) Serbian (Latin, Serbia) Swedish (Finland) Azeri (Cyrillic, Azerbaijan) Malay (Brunei Darussalam) Uzbek (Cyrillic, Uzbekistan) Arabic (Egypt) Chinese (Hong Kong S.A.R.) German (Austria) English (Australia) Spanish (Spain) French (Canada) Serbian (Cyrillic, Serbia) Arabic (Libya) Chinese (Singapore) German (Luxembourg) English (Canada) Spanish (Guatemala) French (Switzerland) Arabic (Algeria) Chinese (Macao S.A.R.) German (Liechtenstein) English (New Zealand) Spanish (Costa Rica) French (Luxembourg) Arabic (Morocco) English (Ireland) Spanish (Panama) French (Principality of Monaco) Arabic (Tunisia) English (South Africa) Spanish (Dominican Republic) Arabic (Oman) English (Jamaica) Spanish (Venezuela) Arabic (Yemen) English (Caribbean) Spanish (Colombia) Arabic (Syria) English (Belize) Spanish (Peru) Arabic (Jordan) English (Trinidad and Tobago) Spanish (Argentina) Arabic (Lebanon) English (Zimbabwe) Spanish (Ecuador) Arabic (Kuwait) English (Republic of the Philippines) Spanish (Chile) Arabic (U.A.E.) Spanish (Uruguay) Arabic (Bahrain) Spanish (Paraguay) Arabic (Qatar) Spanish (Bolivia) Spanish (El Salvador) Spanish (Honduras) Spanish (Nicaragua) Spanish (Puerto Rico) Sami, Southern (Norway) Serbian (Cyrillic, Bosnia and Herzegovina) Zulu Xhosa Frisian (Netherlands) Setswana (South Africa) Sami, Northern (Sweden) Sami, Southern (Sweden) Croatian (Bosnia and Herzegovina) Sami, Inari (Finland) Quechua (Peru) Sami, Northern (Finland) Sami, Skolt (Finland) Welsh Bosnian (Latin, Bosnia and Herzegovina) Bosnian (Cyrillic, Bosnia and Herzegovina) Filipino (Philippines) Sami, Lule (Norway) Mapudungun (Chile) Inuktitut (Latin, Canada) Maori Quechua (Ecuador) Irish (Ireland) Serbian (Latin, Bosnia and Herzegovina) Mohawk (Mohawk) Sami, Lule (Sweden) Luxembourgish (Luxembourg) Sesotho sa Leboa (South Africa) Quechua (Bolivia) Sami, Northern (Norway) Maltese Romansh (Switzerland)
Your browser Culture : English (United States) Current Culture : English (United States)
English (United States)
Download sample
Quick Start
AutoPostBack
DataGrid
Minimum/Maximum Dates
Globalization
Custom Style
Dynamic Creation
Misc. Properties
Special Dates
Advanced Min/Max Dates
DayRender
Validators
XHTML, Section 508 & WAI
<%@ Page language="c#" Codebehind="Sample15.aspx.cs" AutoEventWireup="false" Inherits="BasicFrame.WebSamples.BasicDatePicker.CS.Sample15" %> <%@ Register TagPrefix="bdp" Namespace="BasicFrame.WebControls" Assembly="BasicFrame.WebControls.BasicDatePicker" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>BDPLite : Globalization</title> </head> <body> <form id="form1" method="post" runat="server"> <h3>BDPLite : Globalization</h3> <p>Pick a Date:<br /><BDP:BDPLite id="BDPLite1" runat="server"></BDP:BDPLite></p> <p> Culture:<br /> <asp:DropDownList id="ddlCultures" runat="server"></asp:DropDownList></p> <p><asp:Button id="Button1" runat="server" Text="Button"></asp:Button></p> <p><asp:Label id="Label1" runat="server"></asp:Label><br /> <asp:Label id="Label4" runat="server"></asp:Label></p> <p><asp:Label id="Label2" runat="server"></asp:Label><br /> <asp:Label id="Label3" runat="server"></asp:Label></p> </form> </body> </html>
Imports System.Globalization Imports BasicFrame.WebControls Public Class Sample15 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 BDPLite1 As BasicFrame.WebControls.BDPLite Protected WithEvents ddlCultures As System.Web.UI.WebControls.DropDownList Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents Label4 As System.Web.UI.WebControls.Label Protected WithEvents Label2 As System.Web.UI.WebControls.Label Protected WithEvents Label3 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 ' Declare CultureInfo object. Be sure to include System.Globalization Namespace. Dim requestCulture As CultureInfo Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 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)) ' Set CurrentThread to CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = requestCulture Catch ' Return server Culture if none available in HttpHeaders. ' Do nothing as BDPLite will pickup default server CurrentThread; End Try Me.BDPLite1.SelectedDate = DateTime.Today ' set BDP DateFormat to display Culture dependent ShortDate pattern Me.BDPLite1.DateFormat = DateFormat.ShortDate ' print out User Agent Culture. Label2.Text = "Your browser Culture : <blockquote><strong>" + requestCulture.DisplayName + "</strong></blockquote>" Label3.Text = "Current 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() ' 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 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Create a Culture object from the item selected in the DropDownlList ' and set CurrentThread to new CultureInfo object. System.Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo(ddlCultures.SelectedValue) Label1.Text = "You picked: <strong>" + Me.BDPLite1.SelectedDateFormatted + "</strong>" Label3.Text = "Current Culture: <blockquote><strong>" + System.Threading.Thread.CurrentThread.CurrentCulture.DisplayName + "</strong></blockquote>" Label4.Text = "Current ShortDate pattern: <strong>" + System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern + "</strong>" End Sub End Class
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Globalization; using BasicFrame.WebControls; namespace BasicFrame.WebSamples.BasicDatePicker.CS { /// <summary> /// BDPLite : Globalization /// </summary> public class Sample15 : System.Web.UI.Page { protected System.Web.UI.WebControls.Label Label4; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.DropDownList ddlCultures; protected System.Web.UI.WebControls.Label Label3; protected System.Web.UI.WebControls.Label Label2; protected BasicFrame.WebControls.BDPLite BDPLite1; protected System.Web.UI.WebControls.Button Button1; // Declare CultureInfo object. Be sure to include System.Globalization Namespace. CultureInfo requestCulture; private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { // 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]); // Set CurrentThread to CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = requestCulture; } catch { // Return server Culture if none available in HttpHeaders. // Do nothing as BDPLite will pickup default server CurrentThread; } this.BDPLite1.SelectedDate = DateTime.Today; // set BDP DateFormat to display Culture dependent ShortDate pattern this.BDPLite1.DateFormat = DateFormat.ShortDate; // print out User Agent Culture. Label2.Text = "Your browser Culture : <blockquote><strong>" + requestCulture.DisplayName + "</strong></blockquote>"; Label3.Text = "Current Culture : <blockquote><strong>" + requestCulture.DisplayName + "</strong></blockquote>"; BindCultureList(); } } private void BindCultureList() { // Get all Cultures from the .NET Framework this.ddlCultures.DataSource = CultureInfo.GetCultures(CultureTypes.SpecificCultures); this.ddlCultures.DataValueField = "Name"; this.ddlCultures.DataTextField = "DisplayName"; this.ddlCultures.DataBind(); // Loop through all the Cultures in the DropDownList and select the current culture. foreach(ListItem item in ddlCultures.Items) { if(item.Value == requestCulture.Name) item.Selected = true; else item.Selected = false; } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { // Create a Culture object from the item selected in the DropDownlList // and set CurrentThread to new CultureInfo object. System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(ddlCultures.SelectedValue); Label1.Text = "You picked: <strong>" + this.BDPLite1.SelectedDateFormatted + "</strong>"; Label3.Text = "Current Culture: <blockquote><strong>" + System.Threading.Thread.CurrentThread.CurrentCulture.DisplayName + "</strong></blockquote>"; Label4.Text = "Current ShortDate pattern: <strong>" + System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern + "</strong>"; } } }
See Also
TextBoxReadOnly | NullDateText