
Introduction
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">
</DP:MyOwnWebControls.DatePickerControl>
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:
Property | Type | Defaultvalue | Description |
Text | String | | The content of the DatePicker edit field. |
RelPath | String | ../ | Relative path to the locations of the DatePicker images, beginning from the page with the DatePicker object. |
Tooltip | String | | A tooltip. |
Width | String | 64px | Width in pixels. |
CheckFunc | String | CheckDatePickerDate | The 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 . |
Disabled | Boolean | False | Decides 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:
Parameter | Type | Defaultvalue | Description |
Page | ByRef System.Web.UI.Page | | Page where the DatePicker is. |
oSession | ByRef As System.Web.SessionState. HttpSessionState | | Active Session object. |
id | String | | The ID of the object. |
value | String | | Active date. |
relpath | String | ../ | Relative path to the locations of the DatePicker images beginning from the page with the DatePicker object. |
tooltip | Optional String | | The tooltip. |
width | Optional String | 64px | Width in pixels. |
bVisible | Optional Boolean | True | Visibility. |
bDisabled | Optional Boolean | False | Decided if it's a read-only control. |
checkfunc | Optional String | CheckDatePickerDate | The 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 . |
History
- 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.
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