download code here
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 include on.
Solution
In this post i will explain you how i have embedded javascript , images and style sheet to my previous article . How to: Create a Date Picker Composite Control in ASP.NET (C#). Also i have added another property to 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 defaults its been set to "%d/%m/%Y" which is DMY.
How to embed ?
I added to the project images, java scripts, 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 Style Sheet
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 following line inside OnInit function
_ImgDate.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "DatePicker.Resources.CalendarIcon.gif");
add these functions indise OnInit function
AddStyleSheet(); AddJavaScript("DatePicker.Resources.prototype.js"); AddJavaScript("DatePicker.Resources.calendarview.js");
and that is our date picker control is ready to use you can drag and drop on any page and start using it.
Your feedback is welcome.

Comments
No response to “Asp.net date picker control part 2”
Post Comments (Atom)
Post a Comment |
Post a Comment