Click here to Skip to main content
13,046,045 members (46,019 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 22 Sep 2006

Ready to Use DatePicker Custom Control

, 22 Sep 2006
Rate this:
Please Sign up or sign in to vote.
DatePicker WebControl based on the DatePicker of Guyon A. Roche.

Sample Image - DatePickerCustomControl.jpg


The article of Nikita D. Sinelnikoff and the source code of Guyon A. Roche inspired me to encapsulate the DatePicker inside a .NET Custom Control.

In addition, the source code of Nikita contained some mistakes, and I still had some useful extension ideas.

Bug fixes on Nikita's code and extensions

  • If I click on the "Next Week" button, there is a missing object in JavaScript. I found that the function getDaysInMonth doesn't exist.
  • Problem of dynamic positioning of the span tag.
  • I extended the code with some nice colors. In this connection, I think it's a good idea to highlight the actual date.
  • I added a check function on the input-field that checks the date for correct input if the user enters a date manually.
  • I extended the class for multi-language support.
  • I encapsulated all the functions in a custom control written in VB.NET.

How to use

There are the steps to use the control:

  • Modify the DatePickerDynObject.GetLabels method if you want multi-language support. I can not post here the translation component I use in the real product environment!!! Maybe my article to generate multi-language websites very easily can help you.
  • Copy MyOwnWebControls.dll in your solution bin folder and/or create a .NET Reference.
  • Copy the Images and Js folders to your project folder.
  • In your aspx or ascx file, append a line to publish the control, like this:
  • <%@ Register TagPrefix="DP" NameSpace="MyOwnWebControls" Assembly="MyOwnWebControls" %>
  • Create an object in your aspx or ascx file, like this:
  • <DP:MyOwnWebControls.DatePickerControl id="DP_whatever_date" 
       Width="100px" RelPath="../" runat="server">
  • Create a server side variable in the code-behind:
  • Protected DP_whatever_date As MyOwnWebControls.MyOwnWebControls.DatePickerControl

Description of properties

The Custom Control supports these properties:

TextString The content of the DatePicker edit field.
RelPathString../Relative path to the locations of the DatePicker images, beginning from the page with the DatePicker object.
TooltipString A tooltip.
WidthString64pxWidth in pixels.
CheckFuncStringCheckDatePickerDateThe JS function to check the user input. You can write your own CheckMethod for specialized checks. The JS function must have only one parameter (the object ID) and returns true/false.
DisabledBooleanFalseDecides if it's a read-only control

Special use mode

In my company, we often use the code-behind to generate some HTML objects with static HTML text and put this text inside a PlaceHolder with a LiteralControl. The DatePicker supports this feature too. It means, you can use the internal DatePickerDynObject class and call the GenerateDatePicker method to produce the core HTML stream used for the LiteralControl. Here comes some example code:

Dim oDP As New TXTChainWebControls.DatePickerDynObject
Dim oLiteral as LiteralControl

oLiteral = new LiteralControl (oDP.GenerateDatePicker(Me, Session, _
           "DP_whatever_date", "24.12.2006", "../"))

This method supports the following parameters:

PageByRef System.Web.UI.Page Page where the DatePicker is.
oSessionByRef As System.Web.SessionState. HttpSessionState Active Session object.
idString The ID of the object.
valueString Active date.
relpathString../Relative path to the locations of the DatePicker images beginning from the page with the DatePicker object.
tooltipOptional String The tooltip.
widthOptional String64pxWidth in pixels.
bVisibleOptional BooleanTrueVisibility.
bDisabledOptional BooleanFalseDecided if it's a read-only control.
checkfuncOptional StringCheckDatePickerDateThe JS function to check the user input. You can write your own CheckMethod for specialized checks. The JS function must have only one parameter (the object ID), and returns true/false.


  • 27.09.2006 - Bug fix.
    • Solved the overlay problem with static listboxes (no z-order support for dynamically created listboxes).
  • 22.09.2006 - Initial version.


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


About the Author

Stephan Pilz
Web Developer
Germany Germany
I started 1987 when I was about 14 years old, with Basic and Pascal on 8Bit Atari with insanely 130KB of memory, later 16Bit Atari (4Megs). In study I learn C, C++, Modula-2, Assembler and other science languages (Prolog, ADA). I hold a german engineer's degree Dipl.-Ing. (FH) in "Technical Computer Science" from the University of Applied Sciences Mittweida, Germany (comparable with a Master Degree).

Now I develop PPS and Supply-Chain-Software for middle and great companies in Chemnitz/Germany with Web- and MFC-Frontends in C, C++, ASP.NET, ADO.NET, XML, HTML, JavaScript.

My main tasks are specify and write down solutions of problems and implement the first code snippets.

In my spare time I like to drive a (fast) motocycle, read many science fiction and fantasy books and I'm a enthusiastically shotokan karate fighter. In winter I falling down from hill with alpin ski on foots, because snowboards are only for drug sniffers Wink | ;-)

You may also be interested in...


Comments and Discussions

QuestionDesignTime View Pin
Lloyd Gregory16-Aug-07 8:19
memberLloyd Gregory16-Aug-07 8:19 
GeneralWrong date Pin
rtomaska24-Apr-07 4:41
memberrtomaska24-Apr-07 4:41 
GeneralReturn mm.dd.yyyy Pin
Patrick7572-Nov-06 20:22
memberPatrick7572-Nov-06 20:22 
AnswerRe: Return mm.dd.yyyy Pin
Stephan Pilz6-Nov-06 22:34
memberStephan Pilz6-Nov-06 22:34 
GeneralReturn mm.dd.yyyy Pin
Patrick7572-Nov-06 20:22
memberPatrick7572-Nov-06 20:22 
QuestionQuestions Pin
Misty_Blue11-Oct-06 4:25
memberMisty_Blue11-Oct-06 4:25 
QuestionRe: Questions Pin
Misty_Blue11-Oct-06 4:45
memberMisty_Blue11-Oct-06 4:45 
AnswerRe: Questions Pin
Stephan Pilz11-Oct-06 4:46
memberStephan Pilz11-Oct-06 4:46 
GeneralVS 2005 web application Pin
yososndr4-Oct-06 3:57
memberyososndr4-Oct-06 3:57 
GeneralRe: VS 2005 web application Pin
Stephan Pilz4-Oct-06 23:57
memberStephan Pilz4-Oct-06 23:57 
GeneralRe: VS 2005 web application Pin
Misty_Blue11-Oct-06 4:23
memberMisty_Blue11-Oct-06 4:23 
GeneralView State on disabled datepicker not working Pin
jvetterli1-Oct-06 18:54
memberjvetterli1-Oct-06 18:54 
GeneralRe: View State on disabled datepicker not working Pin
Stephan Pilz5-Oct-06 0:03
memberStephan Pilz5-Oct-06 0:03 
QuestionZ-Index Pin
jvetterli26-Sep-06 10:08
memberjvetterli26-Sep-06 10:08 
AnswerRe: Z-Index Pin
Stephan Pilz26-Sep-06 20:52
memberStephan Pilz26-Sep-06 20:52 
AnswerRe: Z-Index Pin
Stephan Pilz26-Sep-06 21:55
memberStephan Pilz26-Sep-06 21:55 
GeneralRe: Z-Index Pin
jvetterli27-Sep-06 10:04
memberjvetterli27-Sep-06 10:04 
Generaltypo error.. Pin
Ramu -15626-Sep-06 3:12
memberRamu -15626-Sep-06 3:12 
GeneralRe: typo error.. Pin
Stephan Pilz26-Sep-06 4:04
memberStephan Pilz26-Sep-06 4:04 

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 | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 22 Sep 2006
Article Copyright 2006 by Stephan Pilz
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid