Click here to Skip to main content
Licence CPOL
First Posted 2 Jul 2009
Views 32,884
Downloads 0
Bookmarked 33 times

ASP.NET date picker control - Part 2

By Salmanzz | 24 Aug 2009 | Technical Blog
In this post, I will explain you how I have embedded JavaScript, images and stylesheet to my previous article.

1

2
3 votes, 33.3%
3
1 vote, 11.1%
4
5 votes, 55.6%
5
4.53/5 - 9 votes
μ 4.53, σa 1.70 [?]

image

Introduction

In my previous post How to: Create a Date Picker Composite Control in ASP.NET (C#), I explained how to work with ASP.NET composite control to create a date picker control for ASP.NET.

Problem

However to use that control you still require JavaScript, style and images to be included.

Solution

In this post, I will explain you how I have embedded JavaScript, images and stylesheet to my previous article, How to: Create a Date Picker Composite Control in ASP.NET (C#). I have also added another property to the control which is how to change date format for the control. You can download the code, drag and drop it and start using it inside data navigation controls or anywhere in your ASP.NET web application.

Property

  • DateFormat - By default, it's been set to "%d/%m/%Y" which is DMY.

How to Embed ?

I added to the project images, JavaScripts, and styles that I need for my date picker control. Click on each file properties and change Build Action from Content to Embedded Resource, then modify the AssemblyInfo.cs as below:

[assembly: System.Web.UI.WebResource("DatePicker.Resources.calendarview.css", "text/css")]
[assembly: System.Web.UI.WebResource("DatePicker.Resources.calendarview.js", "text/js")]
[assembly: System.Web.UI.WebResource("DatePicker.Resources.CalendarIcon.gif", "img/gif")]
[assembly: System.Web.UI.WebResource("DatePicker.Resources.prototype.js", "text/js")]

Note: The format of embedded resources is very important which is:

[Assembly Name].[Folder].[File Name]

To Embed JavaScript

To embed JavaScript, I have created a function called AddJavaScript(string javaScriptFile) which is:

private void AddJavaScript(string javaScriptFile)
    {
        string scriptLocation = Page.ClientScript.GetWebResourceUrl
		(this.GetType(),javaScriptFile );
        Page.ClientScript.RegisterClientScriptInclude(javaScriptFile, scriptLocation);

    }

To Embed Stylesheet

private void AddStyleSheet()
     {
         string includeTemplate = "<link rel='stylesheet' text='text/css' href='{0}' />";
         string includeLocation =
               Page.ClientScript.GetWebResourceUrl
		(this.GetType(), "DatePicker.Resources.calendarview.css");
         LiteralControl include = new LiteralControl
				(String.Format(includeTemplate, includeLocation));
         Page.Header.Controls.Add(include);
     }

To Embed Image

Just add the following line inside the OnInit function:

_ImgDate.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), 
			"DatePicker.Resources.CalendarIcon.gif");

Add these functions inside the OnInit function:

AddStyleSheet();
AddJavaScript("DatePicker.Resources.prototype.js");
AddJavaScript("DatePicker.Resources.calendarview.js");

And that is our date picker control ready to use. You can drag and drop on any page and start using it.

View this article on my blog.

Your feedback is welcome.

License

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

About the Author

Salmanzz

Software Developer (Senior)
BMJ
United Kingdom United Kingdom

Member


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
GeneralError: Microsoft JScript runtime error: Object doesn't support this property or method PinmemberDaniel Kamisnki16:50 4 Dec '09  
Generalnice on.. PinmemberRajesh Pillai14:27 24 Aug '09  
GeneralRe: nice on.. PinmemberSalmanzz1:47 25 Aug '09  
GeneralAnother issue I'd like to solve PinmemberPhyllis Smith17:18 15 Aug '09  
GeneralRe: Another issue I'd like to solve PinmemberSalmanzz9:21 16 Aug '09  
GeneralProblem with adding validators PinmemberPhyllis Smith16:55 14 Aug '09  
GeneralRe: Problem with adding validators PinmemberSalmanzz1:32 15 Aug '09  
GeneralRe: Problem with adding validators PinmemberPhyllis Smith3:19 15 Aug '09  
QuestionVery good - but the calender is placed abowe the page? Pinmemberpalsbo0:46 22 Jul '09  
AnswerRe: Very good - but the calender is placed abowe the page? PinmemberSalmanzz0:59 22 Jul '09  
GeneralThanks great control Pinmemberwtf_imanut9:35 21 Jul '09  
GeneralRe: Thanks great control PinmemberSalmanzz0:28 22 Jul '09  
GeneralRe: Thanks great control Pinmemberwtf_imanut9:34 27 Jul '09  
GeneralRe: Thanks great control PinmemberSalmanzz0:42 28 Jul '09  
GeneralGood Work! Pinmemberprasad024:19 2 Jul '09  
GeneralRe: Good Work! PinmemberSalmanzz5:56 2 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
Web04 | 2.5.120209.1 | Last Updated 24 Aug 2009
Article Copyright 2009 by Salmanzz
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid