Click here to Skip to main content
6,597,576 members and growing! (22,019 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

Using ASP.NET calendar for web applications.

By Andrew Golik

Using ASP.NET calendar for web applications.
Windows, .NET, ASP.NET, Visual Studio, Dev
Posted:27 Jan 2007
Views:24,324
Bookmarked:13 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
10 votes for this article.
Popularity: 3.53 Rating: 3.53 out of 5
1 vote, 10.0%
1
1 vote, 10.0%
2
1 vote, 10.0%
3
1 vote, 10.0%
4
6 votes, 60.0%
5

Sample Image - Calendar.jpg

Introduction

The calendar control is the most used control for business applications. There is now way to avoid this. If you are using environment where there isn’t such control you have to buy it from outside developers or spend your time implementing it yourself. The article describes the usage of calendar control inside static html page. I faced needs to use calendar control when I had chance to program in ASP environment. I hope you found it useful.

Using the calendar control

The calendar is implemented as standalone asp.net application. So any outside application in IIS can use this functionality. It’s implemented as modal window.
function showCalendar(callbackHandler)
{
 
 
      window.showModalDialog("CalendarModal.htm", callbackHandler,
          "center:yes;help:no;scroll:no;dialogHeight:260px;dialogWidth:230px;");
 
}
The calendarModal.htm contains iframe that nests a ASP.NET calendar control. It was necessary to do this because of behaivor of IE Modal window. You can not nest form inside modal window. I mean actually you can do this but it makes post into new window and “target” attribute in form tag is ignored. So you can not specify “_self” target there as it’s ignored.
<script type="text/javascript" >
  
  function onLoadCalendarWnd()
  {
     var result = uxCalendarFrame.document.getElementById("uxResult").innerText;
     if(result!="Not Set")
     {
         var callbackHandler = window.dialogArguments;
         callbackHandler(result);
     }
 } 
 
</script>
<body style="margin:0px;" >
  <iframe id="uxCalendarFrame" frameborder="0" width="100%" height="100%"
       scrolling="no"  onload="onLoadCalendarWnd()" src="Calendar.aspx"></iframe>
</body>
</html>
This iframe contains onload event to call callback function passed into modal window and to cause closing the window in case of date selection.
Passing callback function as dialogArguments.
 function startDateCallbackHandler(date)
 {
      
     uxStartDate.value = date;
 
 }
 function endDateCallbackHandler(date)
 {
     
     uxEndDate.value = date;
 }
 function showCalendar(callbackHandler)
 {
 
 
      window.showModalDialog("CalendarModal.htm", callbackHandler,
          "center:yes;help:no;scroll:no;dialogHeight:260px;dialogWidth:230px;");
 
   
 }

<a href="javascript:showCalendar(startDateCallbackHandler)">Start Date:</a> 
      <input id="uxStartDate"    />
 <a href="javascript:showCalendar(endDateCallbackHandler)">End Date:</a>
      <input id="uxEndDate"   />
As you can see each date input has its own callback handler.

The server side

The calendar page contains only one event handler to indicate that data selection happens. The default value of uxResult is “Not Set”.
  protected void uxCalendar_SelectionChanged(object sender, EventArgs e)
    {

        uxResult.Text = uxCalendar.SelectedDate.ToShortDateString();
       

    }

The value is also used as flag that causes not to close the calendar. Once you have selected the date the modal window is closed.

License

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

About the Author

Andrew Golik


Member
Andrew Golik is a software professional working in Minsk, Belarus.
He enjoys design infrastructures based on object oriented paradigm. His programming experience includes ASP, ASP.NET, .NET, COM, JAVA, PHP, DHTML, AJAX, blah blah blah....

He is developer at TargetProcess Project (www.targetprocess.com).
The TargetProcess is an agile project management tool that makes your life easy when do agile. He also has the developer blog at http://andrewgolik.wordpress.com
Occupation: Web Developer
Location: Belarus Belarus

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralVersioning Pinmemberstixoffire1:16 28 Mar '07  
GeneralRe: Versioning Pinmemberandrew.golik2:38 28 Mar '07  
GeneralRe: Versioning Pinmemberstixoffire8:26 28 Mar '07  
GeneralRe: Versioning Pinmemberandrew.golik0:00 29 Mar '07  
Generalhuge picture Pinmemberdnh13:50 27 Jan '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Jan 2007
Editor: Sean Ewington
Copyright 2007 by Andrew Golik
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project