Click here to Skip to main content
Licence CPOL
First Posted 23 Dec 2007
Views 19,214
Bookmarked 28 times

ASP.NET(C#) calendar

By , | 10 Jan 2008 | Article
Pop Up calendar in C# ASP.NET2.0

Introduction

We often need a calendar to give user a way to select date.We know that we have lots of JavaScript calendar already available in the market.But some time we need a calendar from where we can protect user to select only few date not all date and the best use for that is ASP.NET calendar control we can do lots of function with asp.net calendar control...like bind date from database etc which hard to do with JS calendar.

Background

Here is the few key feature of this asp.net popup calendar....

1>show the calendar by finding out the anchor position.

2>Auto hiding the calendar on focus out work for IE,Firefox and other

3>Customize the calendar control as you want

Using the code

In the page where you want to add the calendar just use this type of code in body....

            <asp:TextBox runat="server" ID="Date" ToolTip="Please select the date that the site was installed"></asp:TextBox>                      

<a id="cananc" href="javascript:opencal();">

                                            <img src="calendar/cal.jpg" alt="Click here to select a date" width="20" height="20"

                                                border="0"></a>

 

now at the top of that page use the following code..... 

 

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

  <script type="text/javascript" language="javascript">

  

  var calendar_window=window;

  

  function opencal()

  {//get the anchor position

    var myac=getAnchorWindowPosition('cananc');

    

    calendar_window=window.open('calendar/calendar.aspx?formname=form1.Date','calendar_window','width=200,height=250,Top='+myac.y+',Left='+myac.x+'');

    calendar_window.focus();

  }

  

  



//set the click hander on the main window

if (window.captureEvents){ // for firefox

  

    window.captureEvents(Event.CLICK);



    window.onclick= handle;

}

else

document.onclick=handle; // for IE as in IE captureEvents does not work



function handle(e) {

   if(calendar_window.name=='calendar_window')

        {

            calendar_window.close();

        }

}





  </script> <o:p />

Remember to send form id to the calendar.aspx page while opening the popup.

License

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

About the Authors

JosephL

Web Developer
JLAZTech.com
United States United States

Member



Arnab Dutta

Software Developer

India India

Member

My aim of life is to become a successful professional in the field of Information Technology and to work in an innovative and competitive world.
 
I have taken my B.Tech (IT) from RCCIIT kolkata India 2006 batch. Currently working on ASP.NET (C#),SQL Server2005,Mysql4,MS AJAX freamwork
 
"Challenges are what make life interesting;
overcoming them is what makes life meaningful. "

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
    Layout  Per page   
  Refresh
GeneralIts Calendar not Calender Pinmembercodedeveloper2218:14 3 Jan '08  
Generalwelcome to Codeproject Pinmember Abhijit Jana18:58 23 Dec '07  

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.120517.1 | Last Updated 10 Jan 2008
Article Copyright 2007 by JosephL, Arnab Dutta
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid