Article
Beginning ASP.NET Using VB.NET - Chapter 14: ASP.NET Server Controls
Try It Out -- MyCalendar
In the previous sections of this chapter, you were exposed to many of the most common ASP.NET server controls, including the Calendar control. Many web sites, particularly personal home pages, share information regarding upcoming events. For example, a local soccer team might have a web site that displays the team's game schedule for the players, parents, coaches, and so on; or a band might display an on-line calendar that shows all upcoming gigs for their fans. In either case, the ability to render intuitive and familiar calendar-related events or appointments on a web page is crucial.
Due to the centrality of the calendar to many situations, we've decided to base this Try It Out around the Calendar control. We're not going to try to replicate the advanced features of a desktop calendaring tool, such as Microsoft Outlook though. The object of our application will be to share some key dates and appointments on the Web, in the context of a familiar calendar.
To flesh this out a little, here's a mini-specification of some of the features we'll be implementing for the MyCalendar application:
- The
Calendarcontrol should read our calendar data from an XML file (we'll be using the XML file as a data source). This will make it easy to update and change the calendar data, without ever having to change the ASPX file. Due to this, none of our appointments or events will be hard-coded within the ASPX page itself. - We'd like to be able to see several events within a day.
- While we obviously want to see the title of an event or appointment on the calendar, we also want to see some additional information (for example, a detailed description of the event and the start/end time). To enable this, when we click on the event link, a listing of all details should appear.
- Although the
Calendarcontrol defaults to Sunday as the first day of the month, we want the first day of the month to be Monday. - Weekends should display in a slightly different shade (so we know they're coming!), as should days that are part of the previous or next month.
Since we're taking all our information from an XML file, let's begin by looking at the XML that we're going to use.
The XML Source -- MyCalendar.xml
The source XML file we shall use will just contain the basic information we want display in the Calendar control. The MyCalendar.xml file, as with all the listings throughout this book, is available for download on www.wrox.com. The following excerpt of the MyCalendar.xml file is provided, just to show you the XML syntax used, as well as some of the sample data:
<MyCalendar>
<Event>
<ShortDesc>Concert at the Riverfront</ShortDesc>
<DetailDesc>4th of July celebration. Bring stand and a jacket.
</DetailDesc>
<EventDate>2001/07/04</EventDate>
<StartTime>9:30PM</StartTime>
<EndTime>11:00PM</EndTime>
</Event>
<Event>
<ShortDesc>CCT Rehearsal - Brigadoon</ShortDesc>
<DetailDesc>Community Theatre orchestra rehearsal - bring mutes.
</DetailDesc>
<EventDate>2001/07/14</EventDate>
<StartTime>3:30PM</StartTime>
<EndTime>6:30PM</EndTime>
</Event>
</MyCalendar>
The elements of this XML file are fairly straightforward:
MyCalendar-- the root element. XML requires a single root element to contain the child elements.Event-- basically serves as the main parent for each group of elements.ShortDesc-- a short description of the event.DetailDesc-- a detailed description of the event -- could be random notes, comments, or thoughts.EventDate-- the date on which the event occurs. In the sample data, the format used is yyyy/mm/dd, which should serve to eliminate any ambiguity between various local date discrepancies. In fact, because we will use theDateTimeobject to reference this information, any valid format that theDateTimeobject can parse will be acceptable. Having said that, you might prefer to use your local date format -- it's certainly easier to read because that's what you are used to.StartTime-- the time the event starts.EndTime-- the time the event ends.
The rest of the XML file is very similar to this excerpt -- it merely contains information that we are going to reference in our MyCalendar.aspx file. Let's take a look at this now.