To create a master page in Visual Studio, click the 'Website' menu button and then click 'Add New Item...'. When the Add New Item dialog appears, choose 'Master Page' from the list and then give it a name. Then click 'Add'.
Visual Studio will create a file that looks like this:
- <%@ Master Language="VB" CodeFile="myMasterPage.master.vb" Inherits="myMasterPage" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <asp:ContentPlaceHolder id="head" runat="server">
- </asp:ContentPlaceHolder>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
- </asp:ContentPlaceHolder>
- </div>
- </form>
- </body>
- </
If you look at the code, you will see content placeholder controls. These are used by content pages, which are derived from your master pages. Master pages are the page template, and content pages contain the content of your web page.
Content place holders define areas in your master page where the content is replaceable inside your content pages.
To create a content page, go to the Solution Explorer within Visual Studio, and right click on your master page and choose "Add Content Page". This will create a new content page that is linked to the master page you selected. This means that all the content placeholders you created in your master page will appear in your content page.
Note: When dealing with content pages, you can only put content in a content placeholder.
The new content page should look similar to this:
- <%@ Page Title="" Language="VB" MasterPageFile="~/myMasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
Header content goes here - </asp:Content>
- <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Our content goes here. - </asp:Content>
No comments:
Post a Comment