Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

AJAX Date Picker for ASP.NET

0.00/5 (No votes)
17 Feb 2006 1  
AJAX Date Picker is a free ASP.NET 2.0 calendar control which utilizes AJAX techniques and requires no page postbacks.

Sample Image - AJAXDatePicker.gif

Introduction

AJAX Date Picker is a free ASP.NET 2.0 calendar control that utilizes AJAX techniques to get data from the server without an entire page postback. You can specify the clickable dates on a given month as well as other days like holidays, etc. A great application for this control is for those sites that use some reservation system to select valid dates. For example, a travel site can use this control to render only valid dates. This control limits the user on what dates to click. As a result, you have a hybrid client/server validation.

This control is free along with the source code. Feel free to modify the code to suit your needs. If you want to change the look, all you have to do is modify the Default.css file or create your own. Make sure you use the same class names. There is a property called ImageDirectory where you can specify the image directory (the default is images).

Installation

Put Ajax.dll into your bin directory. Make sure you put this code in your web.config in order to enable AJAX communications.

<httpHandlers>
    <add verb="POST,GET" path="ajax/*.ashx" 
         type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>

Make sure you register the control on the pages where you will use it.

<%@ Register Src="AJAXDatePickerControl.ascx" 
                 TagName="AJAXDatePickerControl" TagPrefix="uc1" %>

Put ajaxMethods.cs and DatePicker.cs inside the App_Code directory.

Put AJAXDatePickerControl.ascx and AJAXDatePickerControl.ascx.cs in the root directory of the application.

You can control which dates can be selected, by modifying the ajaxMethods.cs code file under the function:

private Dates GetMonth(DateTime FromDate, DateTime ToDate)
{
    ....
}

Every time you select a month, this function gets fired asynchronously using AJAX. You can write any long running server code here. For example, you can call a web service, or query a database to get the dates.

Other Information

This control uses the Ajax.NET Library by Michael Schwarz.

Please note that I am still ironing out some features and discovering new techniques. As with all ongoing projects, this is a work in progress. Please visit my web site for more updates. Thanks.

For questions or comments, please contact me.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here