Click here to Skip to main content
13,899,494 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


21 bookmarked
Posted 4 Sep 2010
Licenced CPOL

Goodbye Ajax Toolkit, Hello jQuery UI

, 4 Sep 2010
Rate this:
Please Sign up or sign in to vote.
Like most developers, I love finding tools that do my work for me and make me look good. And, like most developers, I am extremely wary of adding too much outside crap to a project which can make maintaining it a nightmare.

Like most developers, I love finding tools that do my work for me and make me look good. And, like most developers, I am extremely wary of adding too much outside crap to a project which can make maintaining it a nightmare. You may end up not only maintaining your own code but someone else's code, or worse, not being able to update the project because a third-party control won't let you.

The Ajax Toolkit has some great stuff that is very easy to use. It's from Microsoft so you can be pretty comfortable adding it to a project. Drag and Drop and off you go. But often things don't work out exactly as you would like. Deploying and debugging are not always easy.

A viable alternative to the Ajax Toolkit is the jQuery UI.

I was happy to see on the jQuery web site they have their own UI controls…very happy. If you are already using jQuery, you don't feel as if you are adding a third party component. And, it seems, Microsoft has 'adopted' jQuery.

Here's their website: It's also reachable from

I decided to try out the DatePicker control, since picking a date is one of the most useful and common tasks a control can do.

Downloading and installing the jQuery UI was no more difficult than downloading and installing jQuery itself. The download is customizable; you pick which components you want and which visual theme you want.

In the download you get:

  • A CSS file and images
  • Minimized versions of the jQuery UI and jQuery code
  • "Development bundle"
    • Documentation
    • Demos
    • Separate code files
    • Misc.

I added the CSS file, image directory and jQuery code file to my project. I already had the jQuery library. When you drag and drop the files onto the page and you'll get entries like these:

<script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.8.4.custom.min.js" type="text/javascript"></script>
<link type="text/css" href="css/smoothness/jquery-ui-1.8.4.custom.css" rel="stylesheet" />

Note: Other versions of the source code are available: non-minimized and documented versions.

Now, let's create a TextBox and hookup the DatePicker control to it:

<asp:TextBox ID="DatePicker_TextBox" runat="server" ></asp:TextBox>

<script type="text/javascript" language="javascript">


     function DocReady()

Note: jQuery code is usually so ugly its own mother would slap it. I strive for legibility and maintainability by NOT nesting an chaining functions and using a more 'traditional' C# style of coding.

Here's what happens when you click on, or tab into, the text box:

Dang, that wasn't hard, it works well and looks pretty. When you select a date, it fills in the textbox:

You can edit the text in the box by hand and the DatePicker control reads it. If the text isn't a valid date, the DatePicker control ignores it. Nice. It has a good solid feel. I know engineers shouldn't talk like that but…it has a good solid feel.

Let's change the date format. Sadly, the date formatting codes are different than the .Net DateTime formatting codes (more on this later). I added a few more options just for fun. For numberOfMonths, you give a two dimensional array: 3 by 4 would show an entire year.


function DocReady()
    var DatePicker = $('#DatePicker_TextBox').datepicker();

                dateFormat: 'DD, d MM, yy',
                numberOfMonths: [1, 2],
                showWeek: 'true'

Why didn't I just chain the formatting code to the creation code? Why did I create a separate variable?

Debugging: If something goes wrong, I can tell if the problem is in the creation of the DatePicker or in the formatting of the DatePicker. Until you have to debug code, you don't know how valuable and useful this is. The local variable avoids a duplicate search operation.

Why the weird code formatting when setting the options?

I tried to make it as readable as possible. When there is more than one option, it is easier to read if each option is on a separate line. It's also easier to tell when the braces and parenthesis match up.

Here's what it looks like with the options set:

Note: In the above image you can see a bug: The fifth day of both months is selected. I checked the website and it was already reported here: The posted workaround corrected the problem.

It's pretty cool. But, the textbox is going to be sent back to the server and will need to be converted to a DateTime object. As mentioned earlier: .NET and jQuery use different formatting codes.

So the code to convert the string to a DateTime is:

String DateText = DatePicker_TextBox.Text;

DateTime TheDate;

// jquery format: DD, d MM, yy
// .Net format:   dddd, d MMMM, yyyy
// Sample:        Friday, 3 September, 2010
if (DateTime.TryParseExact(DateText,
                          "dddd, d MMMM, yyyy",
                          out TheDate) == false)
    TheDate = DateTime.Now.Date;  // handle conversion error

In a real application, you'd want to centralize the format strings in one place so they are easy to maintain (by using constants or utility functions).

Once you start playing with and using the jQuery UI components, you'll be hooked.

By the way, I still use and appreciate the Ajax UpdatePanel in the Ajax Extensions toolbox. Although some treat it disdainfully, what you get, for what you pay, is a great bargain.

I hope someone finds this useful.

Steve Wellens.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Steve Wellens
EndWell Software, Inc.
United States United States
I am an independent contractor/consultant working in the Twin Cities area in Minnesota. I work in .Net, Asp.Net, C#, C++, XML, SQL, Windows Forms, HTML, CSS, etc., etc., etc.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
Ziauddin Tanvir4-Jan-14 9:49
memberZiauddin Tanvir4-Jan-14 9:49 
GeneralMy vote of 1 Pin
Ziauddin Tanvir31-Dec-13 17:08
memberZiauddin Tanvir31-Dec-13 17:08 
GeneralYour vote of 1 is absurd Pin
Steve Wellens1-Jan-14 5:11
memberSteve Wellens1-Jan-14 5:11 
GeneralRe: Your vote of 1 is absurd Pin
Ziauddin Tanvir4-Jan-14 9:37
memberZiauddin Tanvir4-Jan-14 9:37 
GeneralRe: Your vote of 1 is absurd Pin
Steve Wellens4-Jan-14 14:41
memberSteve Wellens4-Jan-14 14:41 
GeneralMy vote of 5 Pin
ratcho10-Sep-13 3:05
memberratcho10-Sep-13 3:05 
GeneralProblems in Jquery datePicker: [modified] Pin
M.Hussain.7-Sep-10 17:58
memberM.Hussain.7-Sep-10 17:58 
GeneralRe: Problems in Jquery datePicker: Pin
Steve Wellens7-Sep-10 18:10
memberSteve Wellens7-Sep-10 18:10 
GeneralRe: Problems in Jquery datePicker: Pin
Irwan Hassan8-Sep-10 6:07
memberIrwan Hassan8-Sep-10 6:07 
GeneralRe: Problems in Jquery datePicker: Pin
M.Hussain.8-Sep-10 18:22
memberM.Hussain.8-Sep-10 18:22 
GeneralRe: Problems in Jquery datePicker: Pin
Steve Wellens9-Sep-10 2:25
memberSteve Wellens9-Sep-10 2:25 
GeneralRe: Problems in Jquery datePicker: Pin
Talking Dotnet29-Sep-10 3:32
memberTalking Dotnet29-Sep-10 3:32 
GeneralDie UpdatePanel Die! Pin
Eric@TouchStar7-Sep-10 4:02
memberEric@TouchStar7-Sep-10 4:02 
GeneralAjaxToolKit and jQuery in same project Pin
devenv.exe6-Sep-10 21:18
professionaldevenv.exe6-Sep-10 21:18 
GeneralRe: AjaxToolKit and jQuery in same project Pin
Steve Wellens7-Sep-10 2:47
memberSteve Wellens7-Sep-10 2:47 
GeneralThat was fun Pin
Yves6-Sep-10 11:34
memberYves6-Sep-10 11:34 
GeneralRe: That was fun Pin
Steve Wellens6-Sep-10 11:48
memberSteve Wellens6-Sep-10 11:48 
GeneralRe: That was fun Pin
Yves6-Sep-10 12:06
memberYves6-Sep-10 12:06 
GeneralJQueryUI Pin
DaveAuld4-Sep-10 20:48
protectorDaveAuld4-Sep-10 20:48 
GeneralRe: JQueryUI Pin
EbenRoux6-Sep-10 18:56
memberEbenRoux6-Sep-10 18:56 
GeneralRe: JQueryUI Pin
DaveAuld6-Sep-10 22:34
protectorDaveAuld6-Sep-10 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190306.1 | Last Updated 4 Sep 2010
Article Copyright 2010 by Steve Wellens
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid