Master 页面:
1 <%@ Master Language="C#" %>
2
3 <script runat="server">
4
5 string m_PageHeadingTitle = "My Company";
6
7 public string PageHeadingTitle
8 {
9 get
10 {
11 return m_PageHeadingTitle;
12 }
13 set
14 {
15 m_PageHeadingTitle = value;
16 }
17 }
18 </script>
19
20 <html xmlns="http://www.w3.org/1999/xhtml" >
21 <head id="Head1" runat="server">
22 <title>My Company Master Page</title>
23 <asp:ContentPlaceHolder id="head" runat="server">
24 </asp:ContentPlaceHolder>
25 </head>
26 <body>
27 <form id="Form1" runat="server">
28 <table cellpadding="3" border="1">
29 <tr bgcolor="silver">
30 <td colspan="2">
31 <h1><%= PageHeadingTitle %></h1>
32 </td>
33 </tr>
34 <tr>
35 <td>
36 <asp:ContentPlaceHolder ID="ContentPlaceHolder1"
37 Runat="server">
38 </asp:ContentPlaceHolder>
39 </td>
40 <td>
41 <asp:ContentPlaceHolder ID="ContentPlaceHolder2"
42 Runat="server">
43 </asp:ContentPlaceHolder>
44 </td>
45 </tr>
46 <tr>
47 <td colspan="2">
48 Copyright 2008 - My Company
49 </td>
50 </tr>
51 </table>
52 </form>
53 </body>
54 </html>
引用页面:
1 <%@ Page Language="C#" MasterPageFile="~/Listing 05-10.master" %>
2 <%@ MasterType VirtualPath="~/Listing 05-10.master" %>
3
4 <script runat="server">
5 protected void Page_Load(object sender, EventArgs e)
6 {
7 Master.PageHeadingTitle = "My Company ?Division X";
8
9 }
10 </script>
11
12 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
13 </asp:Content>
14 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
15 </asp:Content>