728x90
728x170
▶ TimeControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TimeControl.ascx.cs" Inherits="TestProject.TimeControl" %>
<%@ OutputCache Duration="5" VaryByParam="None" %>
<asp:Label ID="timeLabel" runat="server" />
728x90
▶ TimeControl.ascx.cs
using System;
using System.Web.UI;
namespace TestProject
{
/// <summary>
/// 시간 컨트롤
/// </summary>
public partial class TimeControl : UserControl
{
//////////////////////////////////////////////////////////////////////////////////////////////////// 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)
{
this.timeLabel.Text = DateTime.Now.ToString();
}
#endregion
}
}
300x250
▶ MainPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="TestProject.MainPage" %>
<%@ Register TagPrefix="local" Src="~/TimeControl.ascx"
TagName="TimeControl" %>
<!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>OutputCache 지시자 : 캐시 사용하기</title>
</head>
<body>
<form id="form" runat="server">
<div>
현재 시간 (웹 폼) : <asp:Label ID="timeLabel" runat="server" />
<hr />
현재 시간 (사용자 정의 컨트롤) : <local:TimeControl ID="timeControl" runat="server" />
</div>
</form>
</body>
</html>
▶ MainPage.aspx.cs
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)
{
this.timeLabel.Text = DateTime.Now.ToString();
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > ASP.NET' 카테고리의 다른 글
[C#/ASP.NET] DropDownList 클래스 : DataSourceID 속성을 사용해 데이터 소스 바인딩하기 (0) | 2019.12.17 |
---|---|
[C#/ASP.NET] GridView 클래스 사용하기 (0) | 2019.12.16 |
[C#/ASP.NET] WebConfigurationManager 클래스 : 설정 정보 구하기 (0) | 2019.12.16 |
[C#/ASP.NET] ConfigurationManager 클래스 : 설정 정보 구하기 (0) | 2019.12.16 |
[C#/ASP.NET] HttpCachePolicy 클래스 : 코드 기반 캐시 설정하기 (0) | 2019.12.15 |
[C#/ASP.NET] Page 클래스 : Application 속성을 사용해 현재 접속자 수 표시하기 (0) | 2019.12.15 |
[C#/ASP.NET] ASP.NET이 제공하는 상태 관리 기법 (0) | 2019.12.15 |
[C#/ASP.NET] TreeView 클래스 : DataSourceID 속성을 사용해 사이트맵 트리 구조 만들기 (0) | 2019.12.14 |
[C#/ASP.NET] TreeView 클래스 사용하기 (0) | 2019.12.14 |
[C#/ASP.NET] Menu 클래스 : 메뉴 사용하기 (0) | 2019.12.14 |