Datasheet
<form id=”form1” runat=”server”>
<div>
<table border=”0” cellpadding=”0” cellspacing=”0”
style=”width: 100%; height: 100%”>
<tr>
<td colspan=”2” style=”height: 200px”>
<h1>My Company Header</h1>
</td>
</tr>
<tr>
<td style=”width: 200px”>
Menu Goes Here</td>
<td>
<asp:contentplaceholder id=”ContentPlaceHolder1” runat=”server”>
</asp:contentplaceholder>
</td>
</tr>
<tr>
<td colspan=”2” style=”height: 200px”>
Copyright (C) 2006 My Company, All Rights Reserved
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
The first thing you should notice about Listing 1-4 is that it contains a Master directive at the top of the
page. As implied by the codefile and inherits attributes, you can add a code file to the Master Page. Most
of the page is primarily HTML formatting markup.
The other pertinent part of this page is the contentplaceholder element. You can place default content in
here, but content pages will use the id to specify where their content will appear, which will override
any default content.
You can now use this Master Page with any content pages. The process of creating a content page is very
similar to the process required to create any other Web Form. Right-click on the Web project in Solution
Explorer, select Add New Item, select Web Form, accept the suggested name of Default.aspx, check the
Select Master Page option, and click the OK button. Listing 1-5 shows the new content page, after I
modified it.
Listing 1-5: Content page that uses a Master Page: Default.aspx
<%@ Page
Language=”C#”
MasterPageFile=”~/Company.master”
AutoEventWireup=”true”
CodeFile=”Default.aspx.cs”
Inherits=”_Default”
Title=”Content Page” %>
<asp:Content ID=”Content1”
(continued)
13
Hacks Revisited
04_597663 ch01.qxp 4/25/06 9:54 PM Page 13