ASP.NET - Directives - Master
The @Master directive is used in ASP.NET to specify the master page that should be used to define the layout and structure of a content page. A master page typically contains common elements like header, footer, navigation menu, and any other content that should appear on multiple pages. By using a master page, you can create a consistent look and feel across your entire website.
Here's an example of how to use the @Master directive in an ASP.NET content page:
<%@ Page Title="My Page" Language="C#" MasterPageFile="~/MasterPage.master" %>
<!-- Content of the page goes here -->
In this example, the MasterPageFile attribute specifies the path to the master page file (in this case, "MasterPage.master"). The content of the page is placed within the body of the master page using a content placeholder control.
Here's an example of a simple master page in ASP.NET:
<%@ Master Language="C#" %>
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<div id="header">
<!-- Header content goes here -->
</div>
<div id="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
<div id="footer">
<!-- Footer content goes here -->
</div>
</body>
</html>
In this example, the master page contains a header, content area, and footer. The content area is defined using a content placeholder control with the ID "MainContent". This is where the content of the individual pages that use this master page will be inserted.
Here's an example of a content page that uses the above master page:
<%@ Page Title="Home" Language="C#" MasterPageFile="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h1>Welcome to my website!</h1>
<p>This is the home page.</p>
</asp:Content>
In this example, the content of the page is defined within a content block using the ContentPlaceHolderID attribute set to the ID of the content placeholder control on the master page. When this page is rendered, the content defined here will replace the content placeholder in the master page.