■ UserControl 클래스를 사용해 웹 사이트 뼈대를 만드는 방법을 보여준다.
▶ NavigatorUserControl.ascx
1 2 3 4 5 6 7 8 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NavigatorUserControl.ascx.cs" Inherits="TestProject.NavigatorUserControl" %> <div class="text-center"> 내비게이터 </div> |
▶ CategoryUserControl.ascx
1 2 3 4 5 6 7 8 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CategoryUserControl.ascx.cs" Inherits="TestProject.CategoryUserControl" %> <div class="text-center"> 카테고리 </div> |
▶ CatalogUserControl.ascx
1 2 3 4 5 6 7 8 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CatalogUserControl.ascx.cs" Inherits="TestProject.CatalogUserControl" %> <div class="text-center"> 카탈로그 </div> |
▶ CopyrightUserControl.ascx
1 2 3 4 5 6 7 8 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CopyrightUserControl.ascx.cs" Inherits="TestProject.CopyrightUserControl" %> <div class="text-center"> 저작권 </div> |
▶ MainPage.aspx
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 |
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="TestProject.MainPage" %> <%@ Register TagPrefix="local" TagName="NavigatorUserControl" Src="~/NavigatorUserControl.ascx" %> <%@ Register TagPrefix="local" TagName="CategoryUserControl" Src="~/CategoryUserControl.ascx" %> <%@ Register TagPrefix="local" TagName="CatalogUserControl" Src="~/CatalogUserControl.ascx" %> <%@ Register TagPrefix="local" TagName="CopyrightUserControl" Src="~/CopyrightUserControl.ascx" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>UserControl 클래스 : 웹 사이트 뼈대 만들기</title> <link href="Content/bootstrap.css" rel="stylesheet" /> <style> div { border : 1px solid red; padding : 10px; } </style> </head> <body> <form id="form" runat="server"> <div class="container"> <div class="row"> <div class="col-md-12"> <local:NavigatorUserControl ID="navigatorUserControl" runat="server" /> </div> </div> <div class="row" style="height: 200px;"> <div class="col-md-3"> <local:CategoryUserControl ID="categoryUserControl" runat="server" /> </div> <div class="col-md-9"> <local:CatalogUserControl ID="catalogUserControl" runat="server" /> </div> </div> <div class="row"> <div class="col-md-12"> <local:CopyrightUserControl ID="copyrightUserControl" runat="server" /> </div> </div> </div> </form> </body> </html> |
▶ MainPage.aspx.cs
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 |
using System; using System.Web.UI; namespace TestProject { /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 페이지 로드시 처리하기 - Page_Load(sender, e) /// <summary> /// 페이지 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> protected void Page_Load(object sender, EventArgs e) { } #endregion } } |