Localize the jQuery DatePicker Control in an ASP.NET Page

Posted by: Suprotim Agarwal , on 5/13/2010, in Category jQuery and ASP.NET
Views: 69291
Abstract: The jQuery UI DatePicker widget is highly configurable and full of features, and I use it in my applications whenever I can. In this article, we will see how to localize the DatePicker based on the value selected from an ASP.NET DropDownList.
The jQuery UI DatePicker widget is highly configurable and full of features, and I use it in my applications whenever I can. In this article, we will see how to localize the DatePicker based on the value selected from an ASP.NET DropDownList.
For this example, I am using the jQuery UI scripts and CSS hosted on Google CDN. You can always customize your jQuery UI download by selecting the version and specific modules you need from here.
[Note: If you are using jQuery with ASP.NET Controls, you may find my EBook 51 Recipes with jQuery and ASP.NET Controls helpful]
Let us quickly jump to the code and see how to localize the jQuery UI DatePicker control
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Localize a DatePicker</title>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/i18n/jquery-ui-i18n.min.js"
    <script type="text/javascript">
        $(function() {
            $("#ddl").change(function() {
                $('#datepicker').datepicker('option', $.datepicker.regional[$(this).val()]);
    <form id="form1" runat="server">
        <asp:Label ID="lblDate" runat="server" Text="Date: "></asp:Label>
        <asp:TextBox ID="datepicker" runat="server"></asp:TextBox> 
            DataSourceID="odsCulture" runat="server">
            <asp:ListItem Value="">Please select a Language</asp:ListItem>
             <asp:Parameter Name="types" DefaultValue="NeutralCultures" />
As you can see, we start by referencing the jQuery UI CSS theme (jquery-ui.css), jQuery library (jquery.min.js), jQuery UI library (jquery.ui.min.js) and the jQuery Localization file (jquery-ui-i18n.min.js). This localization roll-up file contains a wide range of different translations in it.
There is a DropDownList control(ddl) that is bound to an ObjectDataSource control. This ObjectDataSource control uses the GetCultures() method of the CultureInfo class to retrieves a list of all the culture names supported by the .NET Framework. Here we are using the Neutral culture type - cultures that are associated with a language but are not specific to a country/region.
Note: I have picked up the code for populating the DropDownList with all the culture names, from Stephen Walther’s excellent book ‘ASP.NET 3.5 Unleashed
Let us examine the final piece of code that localizes the DatePicker control based on the value of the DropDownList
<script type="text/javascript">
    $(function() {
        $("#ddl").change(function() {
            $('#datepicker').datepicker('option', $.datepicker.regional[$(this).val()]);
As shown in the code above, the default language is set using  $.datepicker.setDefaults($.datepicker.regional[''])
and then any localizations (in our case English) is applied to a single instance of the datepicker using $("#datepicker").datepicker($.datepicker.regional['en']);
Finally, on the change function() of the DropDownList, we obtain the value of the selected <option> element using [$(this).val() and then pass this value to the $.datepicker.regional option.
When you run the page, the DatePicker localizes the content in English by default
On selecting a Language that the DatePicker localization supports (example Norwegian), the DatePicker localizes the content in Norwegian
Note: If the DatePicker Localization file does not support a language provided in the DropDown, it will ignore the value and display the previously selected content. By the way, you can always easily implement Custom Localization to fill up that gap.
I hope you liked the article and I thank you for viewing it. The entire source code of this article can be downloaded over here
Give me a +1 if you think it was a good article. Thanks!
Recommended Articles
Suprotim Agarwal, ASP.NET Architecture MVP, MCSD, MCAD, MCDBA, MCSE, is the CEO of A2Z Knowledge Visuals Pvt. He primarily works as an Architect Consultant and provides consultancy on how to design and develop .NET centric database solutions.

Suprotim is the founder and primary contributor to DotNetCurry, SQLServerCurry and DevCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

Page copy protected against web site content infringement by Copyscape

User Feedback
Comment posted by Rod Laver on Tuesday, May 18, 2010 5:03 AM
Note that the Norwegian style date picker doesn't have the correct format. Weekdays starts with Monday, not Sunday!
Comment posted by Suprotim Agarwal on Wednesday, May 19, 2010 4:42 AM
Thanks Rod. I didn't know that, but I hope the context of the article is clear to all :-)
Comment posted by Rakesh on Thursday, December 9, 2010 6:10 AM
I Found Free Asp.net datepicker available online.

please check following link to view demo and download.


Comment posted by Jim on Friday, April 29, 2011 2:45 PM
Love your work and have your book - tried your example and calendar did not show till I set the css reference back to 1.7 - disturbing that a widely referenced  lib would have this sort of problem ...
Comment posted by skate safari on Saturday, November 24, 2012 3:46 AM
Very cool... people like you is always saving my day! Thank you!

Post your comment
E-mail: (Will not be displayed)
Insert Cancel