Click here to Skip to main content
Licence CPOL
First Posted 19 Apr 2009
Views 15,712
Downloads 291
Bookmarked 12 times

Date Picker Custom Control in ASP.NET

By sameer_s | 19 Apr 2009 | Unedited contribution
No need to place any image,css,javascript file in project. Only three lines of code can do the wonder.
1 vote, 25.0%
1

2

3

4
3 votes, 75.0%
5
3.00/5 - 4 votes
μ 3.00, σa 3.50 [?]

Introduction

This article is all about the custom control for date picker. This date picker can be used anywhere in asp.net projects. Just go to toolbox. In general section click on 'Choose Item'. Browse for the DatePicker.dll. Add it and you just need to drag drop it on your aspx pages.

Background

I am very thankful to Epoch Calendar for providing javascript & css files. You can refer to it at http://www.javascriptkit.com/script/script2/epoch/index.shtml.

Using the code 

Just go to toolbox. In general section click on 'Choose Item'. Browse for the DatePicker.dll. Add it and you just need to drag drop it on your aspx pages. its reference will be added to Bin by itself. Now you can see a simple textbox in which if you click, you will see a calendar will pop-out.

Just small code segment needs to be added in the aspx page. We need to create a new instance of the calendar. Code snippet is shown as follows. Just add it to the head section of the aspx page or after the page header if you are using usercontrol.

 <script language="javascript" type="text/javascript">
  var calendar1;
  /*must be declared in global scope*/
  /*put the calendar initializations in the window's onload() method*/
  window.onload = function() {
  calendar1 = new Epoch('calendar1','popup',document.getElementById('DatePicker1'),false);
    return;
  }
  </script>
		 

Remember that this method will be called on Onload & this should remain intact as it is otherwise the calendar will not work. You can also do it by adding attributes in code behind.  

Points of Interest

There are lots of other useful custom control which we can make. These controls increases the re usability & save our time to code. Also any change can be made separately and after that the dll can be placed in any project.

History 

Before creating this custom control, user had to place javascript file, css file etc in there project explicitly. If any of these file(s) missed, then our pages shows error(s). Now this problem will not be faced any more.

License

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

About the Author

sameer_s

Software Developer (Senior)
CMMi-3
India India

Member
Working in .NET Technologies from the last +5 years and Exploring myself in .NET by learning, implementing and sharing my ideas of latest topics.
For further queries, shoot me a mail at sameersayani@gmail.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembertienito18:42 29 Dec '10  
Questionhow can I change the format of the date component Pinmemberonr13:33 4 Apr '10  
GeneralPity I cant vote a zero. Pinmemberrobvon17:48 19 Apr '09  
GeneralRe: Pity I cant vote a zero. Pinmembersameer_s21:12 19 Apr '09  
Generali wonder! Pinmemberdsmportal15:05 19 Apr '09  
GeneralRe: i wonder! Pinmembersameer_s2:08 20 Apr '09  
GeneralMy vote of 1 PinmemberSteven Berkovitz12:04 19 Apr '09  
GeneralRe: My vote of 1 Pinmembersameer_s2:12 20 Apr '09  
GeneralRe: My vote of 1 Pinmembermercede19:23 22 Jul '09  
GeneralRe: My vote of 1 Pinmembersameer_s21:22 22 Jul '09  
GeneralRe: My vote of 1 Pinmembermercede8:34 24 Jul '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120209.1 | Last Updated 19 Apr 2009
Article Copyright 2009 by sameer_s
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid