> For the complete documentation index, see [llms.txt](https://brianwu.gitbook.io/brian/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brianwu.gitbook.io/brian/brians-za-ji/za-ji/master.md).

# Master

參考資料:(<https://msdn.microsoft.com/zh-tw/library/wtxbf3hh(v=vs.100).aspx>)

## 主版部分

主版頁面，可以做出一個大致的架構，讓其他頁面去繼承。

主版頁面分為兩個部分，主版頁面本身 & 一個至數個內容頁面。

附檔名 .master (原來為 .aspx)

頁面一開始的識別字 @ Master (原來為 @ Page)

為了內容頁面，留下可置換的空間，該控制項為ContentPlaceHolder。

範例:

```
<%@ Master Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 
    1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" >
    <title>Master page title</title>
</head>
<body>
    <form id="form1" runat="server">
        <table>
           <tr>
               <td><asp:contentplaceholder id="Main" runat="server" /></td>
               <td><asp:contentplaceholder id="Footer" runat="server" /></td>
           </tr>
        </table>
    </form>
</body>
</html>
```

## 內容頁部分

在一開始的識別字後面 要加上 MasterPageFile="所要繼承的主頁路徑"。

例如:

```
<%@ Page Language="C#" MasterPageFile="~/MasterPages/Master1.master" Title="Content Page"%>
```

而內容部分，控制項為Content，並利用ContentPlaceHolderId去對應到主頁ContentPlaceHolder的ID。

範例:

```
<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    Main content.
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
    Footer content.
</asp:content>
```
