Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Chart
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
Search :       Advanced Search »
Home » ASP.NET & Web Forms » Using a JavaScript Calendar Control in Master Pages

Using a JavaScript Calendar Control in Master Pages

This article shows how to use a JavaScript Calendar control in master pages.

Author Rank :
Page Views : 15359
Downloads : 763
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
CalendarUsingJavaScriptwithMastePage.zip
 
 
Nevron Chart
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


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

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
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;
 [Top] Rate this article
 
 About the author
 
Raj Kumar

Raj Kumar is a Microsoft MVP and Senior Software Engineer with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Server 2005/2008, Oracle, WPF, WCF, XAML and Silverlight. He has over 6 years of IT experience working most on Microsoft technologies. He holds Master's degree in Computer Science. When he is not writing code, he likes to write articles and play cricket.

Reach him at raj2511984@gmail.com 

 

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
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.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
good one by Prateek On December 18, 2008
nice job raj
Reply | Email | Modify 
But how would it work in Firefox by Prateek On December 18, 2008
I tried with Explorer and works well. But it is not working at all in firefox. please Reply me at rprateek@hotmail.com
Reply | Email | Modify 
masterpage calendar by suma On February 19, 2009
I's very useful for me. Thx for your post in Master page.
Reply | Email | Modify 
Urgent by Manoj On March 25, 2009
Hello Sir, when i m using this nd clicking on the img(calendar.gif) i m getting Error on the Page. Please help me how can i over come this problem while using calandar with master page.
Reply | Email | Modify 
Re: Urgent by Raj On March 26, 2009
Check controls id in page view source(ctl00_ContentPlaceHolder1_PostedOn).

<
a onclick="showCalendarControl(ctl00_ContentPlaceHolder1_PostedOn)" href="#">
<img src="calendar.gif" style="width: 20px; height: 20px" border=0 />
</a>
Reply | Email | Modify 
Thanks a lot by Asheej On March 28, 2009
Thanks a lot boss....keep posting...
Reply | Email | Modify 
good job by kinfe On May 21, 2009
good job
Reply | Email | Modify 
Not working in Mozilla by satya On June 28, 2009
Hi sir,
Nice post , it is working in IE but not working in Mozilla , So kindly update it .

satya
Reply | Email | Modify 
Re: Not working in Mozilla by Raj On July 16, 2009

Just enclose the control id in single quotes.

Reply | Email | Modify 
Calender control by vijaya On August 26, 2009
Thank u very much to give a such nice code sir,it works fine.it helps me a lot
Reply | Email | Modify 
How to get the selected date into textbox. by raji On February 25, 2010
      How to get the selected date into textbox? Can anybody know.. please help me in this.... Thanks In Advance... Awaiting your reply dotnet buddies...
Reply | Email | Modify 
Re: How to get the selected date into textbox. by Raj On February 22, 2011
TextBox.Text = PostedOn.Value;
Reply | Email | Modify 
Thanks a lot by charu On March 23, 2010
its working good...
Reply | Email | Modify 
Thank you your post was very helpful by Donovan On March 25, 2010
Reply | Email | Modify 
Error on clicking calendar image by Ramesh On August 26, 2010
object Expected error
Reply | Email | Modify 
Re: Error on clicking calendar image by Raj On February 22, 2011
check js file path properly.
Reply | Email | Modify 
Thanks Raj Kumar by Mani On September 4, 2010
Thanks Raj Kumar
Reply | Email | Modify 
Unable to use calendar control by ss On November 24, 2010
Its working fine without giving codes in IE...and wont work with mozilla  .....
As you said i used single codes for the control while calling showcalendarcontrol function...
now calendar control is visible in both the browsers but not working.....ie..selected date is not iserted in textbox
plsssssssss help meeeee
very very urgent
Reply | Email | Modify 
Textbox control by shilpa On February 21, 2011
I want to selected date in Textbox control..
Reply | Email | Modify 
Re: Textbox control by Raj On February 22, 2011
TextBox.Text = PostedOn.Value;
Reply | Email | Modify 
Re: Re: Textbox control by Dorababu On May 26, 2011
Enclosing in single quotes as you said did not work not showing selected date in the text-box in both the browsers
Reply | Email | Modify 
Nice Article by Sunil On May 30, 2011
its a nice article Raj. keep posting...
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.