You can start exploring the ASP.NET job site with the home page. The main function of this page is to display a list of the newest jobs and resumes posted to the site and to display links for posting new jobs and resumes (see Figure 30.1). The complete code for the home page is included in Listing 30.1.
Listing 30.1 Default.aspx
<!-- #INCLUDE Virtual="/aspnetjobs/site/includes/header.aspx" --> <%@ Register TagPrefix="myControls" TagName="NewListings" SRC="/aspnetjobs/site/usercontrols/newlistings.ascx" %> <myControls:Header pageTitle="ASP.NET Jobs" Runat="Server" /> <form runat="Server"> <myControls:UserLinks Runat="Server" /> <table border="0" width="100%" cellpadding="10" cellspacing="20"> <tr><td width="400"> <myControls:NewListings Runat="Server" /> </td><td valign="top"> <img src="site/images/homeimage.gif"> </td></tr> </table> </form> <myControls:Footer Runat="Server" />
The C# version of this code can be found on the CD-ROM.
Figure 30.1. The ASP.NET job site home page.
At the top of the home page in Listing 30.1 is an include directive that includes a file named header.aspx . This file contains page Import directives for importing standard namespaces, such as System.Data and System.Data.SqlClient . It also includes page Register directives for the Header , Footer , and UserLinks user controls. If you know that you'll need to add the same Import and Register directives to several pages, it's much easier to throw all the statements into a single include file.
If you examine the page in Listing 30.1, you'll notice that it includes four user controls: Header , Footer , UserLinks , and NewListings . The Header and Footer user controls are used throughout the job site to render standard content for the top and bottom of each page. For example, the Header user control contains the AdRotator control that renders the banner advertisement at the top of each page.
To learn more about user controls see Chapter 5, "Creating Custom Controls with User Controls."
The UserLinks user control is used to display one of two sets of navigation links. If a user is not authenticated, the UserLinks control displays a link for logging in, a link for listing a new job, and a link for listing a new resume. If, on the other hand, the user of the page is authenticated, the UserLinks control displays a link to the user's home page, a link for listing a new job, and a link for logging out.
Finally, the NewListings user control is used to display the newest jobs and resumes posted to the site. The control contains two DataGrid s, named dgrdNewJobs and dgrdNewResumes , which actually display the new listings.
The NewListings user control uses the Cache object to cache the new job and resume listings between requests . Using the Cache object in this way can dramatically improve the performance of the home page. Performing a database operation can be a slow procedure. By placing the results of the last database operation in the Cache object, you can avoid communicating with the database.
To learn more about the Cache object, see Chapter 17, "Caching ASP.NET Applications."
What happens when the database data changes ? If a person adds a new job or adds a new resume, the cached listings are automatically invalidated. For example, the following statement appears in the ListJob.aspx page:
Cache.Remove( "NewJobs" )
This statement is executed immediately after a new job is added to the database. Because the statement removes the list of new jobs from the Cache object, the job just added appears without any delay on the home page of the job site.