Return to the menu   Select another DES Module

Demonstrates supported date patterns

Use the DateFormat property to override the default short pattern with Abbreviated and Long Formats.

When using a short pattern, you can still allow month name entry with the AllowMonthNames property.

Date patterns are taken from the current culture's CultureInfo.DateTimeFormat property.


Controls

DateFormat=Short, AllowMonthNames=Yes

You can type in the abbreviated month name. It will reformat to show the month number.

...


DateFormat=Short, AllowMonthNames=Shows

You can type either month name or digits. It reformats to show the month abbreviated name.

...


DateFormat=Short, AllowMonthNames=Show+not uppercases

Normally the abbreviated month name is shown in uppercase. You can have it show in as defined in CultureInfo by setting MonthNamesUppercase="false"

...


DateFormat=Abbreviated

...


DateFormat=Long

...




Change the culture:

Source Code (C#)

<script runat="server">
protected void Page_Init(object sender, EventArgs e) { // establish the Page culture in OnInit, not later in OnLoad if (Request.Form[CultureName.UniqueID] != null) // Get the Hidden field value. Its not yet assigned to CultureName.Value in OnInit { PageManager1.CultureName = Request.Form[CultureName.UniqueID]; PageManager1.TransferProperties(); } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Datetextbox1.DateValue = DateTime.Today; Datetextbox2.DateValue = DateTime.Today; Datetextbox3.DateValue = DateTime.Today; Datetextbox4.DateValue = DateTime.Today; Datetextbox5.DateValue = DateTime.Today; } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { // convert to the new culture DateTime vValue1 = Datetextbox1.DateValue; DateTime vValue2 = Datetextbox2.DateValue; DateTime vValue3 = Datetextbox3.DateValue; DateTime vValue4 = Datetextbox4.DateValue; DateTime vValue5 = Datetextbox5.DateValue; CultureName.Value = DropDownList1.SelectedValue; PageManager1.CultureName = CultureName.Value; PageManager1.TransferProperties(); Datetextbox1.DateValue = vValue1; Datetextbox2.DateValue = vValue2; Datetextbox3.DateValue = vValue3; Datetextbox4.DateValue = vValue4; Datetextbox5.DateValue = vValue5; }
</script> <h2>DateFormat=Short, AllowMonthNames=Yes</h2> You can type in the abbreviated month name. It will reformat to show the month number.<br/><br/> <des:DateTextBox ID="Datetextbox1" runat="server" AllowMonthNames="Yes" /> <des:DataTypeCheckValidator ID="DataTypeCheckValidator1" runat="server" ErrorMessage="Bad data" ControlIDToEvaluate="Datetextbox1"/> <br/> <br/> <h2>DateFormat=Short, AllowMonthNames=Shows</h2> You can type either month name or digits. It reformats to show the month abbreviated name.<br/><br/> <des:DateTextBox ID="Datetextbox2" runat="server" AllowMonthNames="Show" /> <des:DataTypeCheckValidator ID="DataTypeCheckValidator2" runat="server" ErrorMessage="Bad data" ControlIDToEvaluate="Datetextbox2"/> <br/> <br/> <h2>DateFormat=Short, AllowMonthNames=Show+not uppercases</h2> Normally the abbreviated month name is shown in uppercase. You can have it show in as defined in CultureInfo by setting <span class="PropertyName">MonthNamesUppercase</span>="false"<br/><br/> <des:DateTextBox ID="Datetextbox3" runat="server" AllowMonthNames="Show" MonthNamesUppercase="False" /> <des:DataTypeCheckValidator ID="DataTypeCheckValidator3" runat="server" ErrorMessage="Bad data" ControlIDToEvaluate="Datetextbox3"/> <br/> <br/> <h2>DateFormat=Abbreviated</h2> <des:DateTextBox ID="Datetextbox4" runat="server" DateFormat="Abbreviated" /> <des:DataTypeCheckValidator ID="DataTypeCheckValidator4" runat="server" ErrorMessage="Bad data" ControlIDToEvaluate="Datetextbox4"/> <br/> <br/> <h2>DateFormat=Long</h2> <des:DateTextBox ID="Datetextbox5" runat="server" DateFormat="Long"/> <des:DataTypeCheckValidator ID="DataTypeCheckValidator5" runat="server" ErrorMessage="Bad data" ControlIDToEvaluate="Datetextbox5"/> <br/> <br/> <des:Button ID="Button1" runat="server"></des:Button><br/> <br/> Change the culture: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem Selected="True" Value="en-US">en-US (United States)</asp:ListItem> <asp:ListItem Value="en-GB">en-GB (Great Britain)</asp:ListItem> <asp:ListItem Value="fr-CA">fr-CA (French in Canada)</asp:ListItem> </asp:DropDownList> <des:PageManager ID="PageManager1" runat="server" CultureName="en-US" /> <asp:HiddenField ID="CultureName" runat="server" Value="en-US" />

Return to the menu   Select another DES Module