■ MasterPage 클래스에서 마스터 페이지를 사용하는 방법을 보여준다.
▶ Site.css
1 2 3 4 5 6 7 8 9 10 11 12 13 |
body { padding-top : 50px; padding-bottom : 20px; } .body-content { padding-left : 15px; padding-right : 15px; } |
▶ MainPage.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<%@ Page Title="MasterPage 클래스 : 마스터 페이지 사용하기" Language="C#" MasterPageFile="~/MainMasterPage.Master" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="TestProject.MainPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server" /> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <div class="jumbotron"> <h1>메인 페이지</h1> <p>마스터 페이지, 레이아웃 페이지 등의 표현 방법은 웹 사이트 공통 레이아웃을 정의하는 기능입니다.</p> </div> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="FooterContent" runat="server" /> |
▶ AboutPage.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<%@ Page Title="정보 페이지" Language="C#" MasterPageFile="~/MainMasterPage.Master" AutoEventWireup="true" CodeBehind="AboutPage.aspx.cs" Inherits="TestProject.AboutPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server" /> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>정보 페이지</h2> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="FooterContent" runat="server" /> |
▶ ContactPage.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<%@ Page Title="연락처 페이지" Language="C#" MasterPageFile="~/MainMasterPage.Master" AutoEventWireup="true" CodeBehind="ContactPage.aspx.cs" Inherits="TestProject.ContactPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server" /> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>연락처 페이지</h2> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="FooterContent" runat="server" /> |
▶ MainMasterPage.Master
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MainMasterPage.Master.cs" Inherits="TestProject.MainMasterPage" %> <!DOCTYPE html> <html lang="ko"> <head runat="server"> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title></title> <link href="Content/bootstrap.css" rel="stylesheet" /> <link href="Content/Site.css" rel="stylesheet" /> <asp:ContentPlaceHolder ID="HeaderContent" runat="server" /> </head> <body> <form id="form" runat="server"> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar" /> <span class="icon-bar" /> <span class="icon-bar" /> </button> <a class="navbar-brand" runat="server" href="~/MainPage.aspx">마스터 페이지</a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a runat="server" href="~/MainPage.aspx">홈</a></li> <li><a runat="server" href="~/AboutPage.aspx">정보</a></li> <li><a runat="server" href="~/ContactPage.aspx">연락처</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a runat="server" href="~/Account/Register">등록</a></li> <li><a runat="server" href="~/Account/Login">로그인</a></li> </ul> </div> </div> </div> <div class="container body-content"> <asp:ContentPlaceHolder ID="MainContent" runat="server" /> <hr /> <footer> <p>© <%: DateTime.Now.Year %> - ASP.NET 웹 프로젝트</p> </footer> </div> <script src="Scripts/jquery-1.9.1.js" /> <script src="Scripts/bootstrap.js" /> <asp:ContentPlaceHolder ID="FooterContent" runat="server" /> </form> </body> </html> |