SIGN UP MEMBER LOGIN:    
ARTICLE

Using a JavaScript Calendar Control in Master Pages

Posted by Raj Kumar Articles | ASP.NET Programming October 20, 2008
This article shows how to use a JavaScript Calendar control in master pages.
Reader Level:

In my previous article JavaScript Calendar in ASP.NET 2.0 here, I discussed how to use a calendar control using java script. I got many emails from readers asking how to use this control with a master page. So here I am going to discuss about this.

In this article I am using a JavaScript file (Calendar.js) and a CSS file (Calendar.css). The JavaScript file has all functions and methods, which are used in calendar and CSS file has all calendar style sheets.

You can call JavaScript file on page like this:

<script language="javascript" src=Calendar.js type="text/javascript"></script>

And style sheet file like this:

<link href=Calendar.css rel="stylesheet" type="text/css">

Only diffrence is you have to change the ID of your control with the master page like this.

This is without the master page.

<form id="form1" runat="server">   
<asp:Label ID="lblDateSent" runat="server" Text="Posted on:" CssClass="graytextbold"></asp:Label>

 <input ID="PostedOn" runat="server" class="NormalTextBox" readonly="readOnly" type="text" />&nbsp;
<a onclick="showCalendarControl(PostedOn)" href="#">
<img src=calendar.gif style="width: 20px; height: 20px" border=0 /></a>
</form>

This is with the master page.

<asp:Label ID="lblDateSent" runat="server" Text="Posted on:" CssClass="graytextbold"></asp:Label>

<
input ID="PostedOn" runat="server" class="NormalTextBox" readonly="readOnly" type="text" />&nbsp;

<
a onclick="showCalendarControl(ctl00_ContentPlaceHolder1_PostedOn)" href="#">
<img src="calendar.gif" style="width: 20px; height: 20px" border=0 />
</a>

Only the changed line is onclick event(showCalendarControl(ctl00_ContentPlaceHolder1_PostedOn)). You can see id of your control in ViewSource.


Result will be same. For more details I am attaching my test application with both examples. Download it.

cal.jpg

Login to add your contents and source code to this article
Article Extensions
Contents added by Raj Kumar on Feb 22, 2011
If you want show selected date in text box then just simply drag and drop a text box on page and put this in text box text.

TextBox1.Text = PostedOn.Value;
share this article :
post comment
 

plz tell me how can i chagne year by using dropdownlist box

Posted by sumit garg Feb 24, 2012

its a nice article Raj. keep posting...

Posted by Sunil Dhiman May 30, 2011

Enclosing in single quotes as you said did not work not showing selected date in the text-box in both the browsers

Posted by Dorababu M May 26, 2011

check js file path properly.

Posted by Raj Kumar Feb 22, 2011

TextBox.Text = PostedOn.Value;

Posted by Raj Kumar Feb 22, 2011
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor