Share via


Substitution 웹 서버 컨트롤 선언 구문

업데이트: 2007년 11월

출력 캐시되는 웹 페이지에서 캐싱 대상에서 제외되는 섹션을 지정합니다. 이 위치에서는 동적 콘텐츠가 검색되어 Substitution 컨트롤을 대체합니다.

<asp:Substitution
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    MethodName="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Visible="True|False"
/>

설명

Substitution 컨트롤을 사용하면 출력 캐시된 웹 페이지에서 컨트롤을 동적 콘텐츠로 대체할 섹션을 지정할 수 있습니다. Substitution 컨트롤은 콘텐츠 대부분이 캐시되는 페이지에서 부분 페이지 캐싱을 하려는 경우에 간단하게 사용할 수 있습니다. 페이지 전체를 출력 캐시한 후 Substitution 컨트롤을 사용하여 캐싱에서 제외할 페이지 부분을 지정하면 됩니다.

Substitution 컨트롤에 대한 자세한 내용은 Substitution 웹 서버 컨트롤 개요를 참조하십시오.

예제

다음 코드 예제에서는 출력 캐시된 웹 페이지에 Substitution 컨트롤을 선언적으로 추가하는 방법을 보여 줍니다. 페이지가 로드되면 레이블 안에 현재 날짜와 시간이 표시됩니다. 이 페이지 섹션은 캐시되고 60초마다 업데이트됩니다. Substitution 컨트롤을 실행하면 GetCurrentDateTime 메서드가 호출되고 GetCurrentDateTime에서 반환된 문자열이 사용자에게 표시됩니다. 페이지에서 이 섹션은 캐시되지 않고 페이지를 새로 고칠 때마다 업데이트됩니다.

<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="VB">  

  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Display the current date and time in the label.
    ' Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString()
  End Sub

  ' The Substitution control calls this method to retrieve
  ' the current date and time. This section of the page
  ' is exempt from output caching. 
  Shared Function GetCurrentDateTime(ByVal context As HttpContext) As String
    Return DateTime.Now.ToString()
  End Function

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution Class Example</title>
</head>
<body>
  <form id="Form1" runat="server">

    <h3>Substitution Class Example</h3>  

    <p>This section of the page is not cached:</p>

    <asp:substitution id="Substitution1"
      methodname="GetCurrentDateTime"
      runat="Server">
    </asp:substitution>

    <br />

    <p>This section of the page is cached:</p>

    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>

    <br /><br />

    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>
<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="C#">  

  void Page_Load(object sender, System.EventArgs e)
  {
    // Display the current date and time in the label.
    // Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString();    
  }

  // The Substitution control calls this method to retrieve
  // the current date and time. This section of the page
  // is exempt from output caching. 
  public static string GetCurrentDateTime (HttpContext context)
  {
    return DateTime.Now.ToString ();
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Substitution Class Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>Substitution Class Example</h3>  

    <p>This section of the page is not cached:</p>

    <asp:substitution id="Substitution1"
      methodname="GetCurrentDateTime"
      runat="Server">
    </asp:substitution>

    <br />

    <p>This section of the page is cached:</p>

    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>

    <br /><br />

    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>

참고 항목

개념

Substitution 웹 서버 컨트롤 개요

참조

Substitution