4. FrmSubstitution.aspx.cs 파일을 열고 다음과 같이 코드를 작성한다. 페이지 로드 시 lblCached Label 컨트롤에 현재 시간을 출력하는 코드다. 현재 시간을 반환해주는 GetCurrentTime 메서드를 작성한다. GetCurrentTime 메서드는 FrmSubstitution.aspx 페이지에서 Substitution1 컨트롤의 MethodName 속성으로 호출된다. 페이지를 새로고침할 때 레이블은 캐싱의 영향을 받아서 60초에 한 번만 변경되고, Substitution 컨트롤은 캐싱의 영향을 받지 않아서 매번 현재 시간이 출력된다.

    ▼  FrmSubstitution.aspx.cs

    using System;
    using System.Web;
    
    namespace DevStandardControl
    {
      public partial class FrmSubstitution : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              // 캐싱되어 출력
              lblCachedLabel.Text = DateTime.Now.ToLongTimeString();
          }
          
          // Substitution 컨트롤에 현재 시간 출력
          public static string GetCurrentTime(HttpContext context)
          {
              return DateTime.Now.ToLongTimeString();
          }
      }
    }
    

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.