BasePartialCachingControl.CachePolicy 속성

정의

래핑된 사용자 정의 컨트롤과 연결된 ControlCachePolicy 개체를 가져옵니다.

public:
 property System::Web::UI::ControlCachePolicy ^ CachePolicy { System::Web::UI::ControlCachePolicy ^ get(); };
public System.Web.UI.ControlCachePolicy CachePolicy { get; }
member this.CachePolicy : System.Web.UI.ControlCachePolicy
Public ReadOnly Property CachePolicy As ControlCachePolicy

속성 값

ControlCachePolicy

래핑된 사용자 정의 컨트롤의 출력 캐싱 관련 속성을 저장하는 ControlCachePolicy입니다.

예제

다음 코드 예제에는 사용자 정의 컨트롤 수 동적으로 로드 및 런타임에 프로그래밍 방식으로 조작 하는 방법을 보여 줍니다. 이 예제에는 다음 세 부분이 있습니다.

  • 기본 클래스 LogOnControl에서 UserControl 상속되고 PartialCachingAttribute 특성이 적용되는 부분 클래스입니다.

  • partial 클래스와 함께 LogOnControl 사용되는 사용자 컨트롤입니다.

  • 사용자 컨트롤을 호스트하는 Web Forms 페이지입니다.

이 예제를 성공적으로 실행 하려면 사용자 정의 컨트롤 파일 (.ascx), 해당 코드 숨김 파일 (.cs 또는.vb) 및 Web Forms 페이지 (.aspx) 사용자 컨트롤을 호스팅하는 동일한 디렉터리에 있는지를 확인 합니다.

예제의 첫 번째 부분에서는 사용자 컨트롤이 런타임에 컨트롤에 의해 PartialCachingControl 래핑되는 것을 의미하는 사용자 컨트롤에 LogOnControl적용되는 방법을 PartialCachingAttribute 보여 줍니다. 개체의 캐싱 설정은 LogOnControl 연결된 ControlCachePolicy 개체를 통해 프로그래밍 방식으로 조작할 수 있으며, 개체를 래핑하는 참조를 PartialCachingControl 통해 사용할 수 있습니다. 이 예제에서는 캐싱 설정은 페이지 초기화 동안 검사할 이며 일부 조건이 충족 될 경우 변경 합니다.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

[PartialCaching(100)]
public class LogOnControl:UserControl
{
    public TextBox user;
    public TextBox password;
}
Imports System.Web.UI
Imports System.Web.UI.WebControls

<PartialCaching(100)> _
Public Class LogOnControl
   Inherits UserControl

   Public user As TextBox
   Public password As TextBox

End Class

이 예제의 두 번째 부분에서는 이전 예제와 함께 사용자 제어 캐싱을 보여 주는 데 사용되는 사용자 컨트롤을 보여 줍니다.

<%@ control inherits = "LogOnControl" src = "LogOnControl.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<table style="font: 10pt verdana;border-width:1;border-style:solid;border-color:black;" cellspacing="15">
<tr>
<td><b>Login: </b></td>
<td><asp:TextBox id="user" runat="server"/></td>
</tr>
<tr>
<td><b>Password: </b></td>
<td><asp:TextBox id="password" TextMode="Password" runat="server"/></td>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>
<%@ control inherits = "LogOnControl" src = "LogOnControl.vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<table style="font: 10pt verdana;border-width:1;border-style:solid;border-color:black;" cellspacing="15">
<tr>
<td><b>Login: </b></td>
<td><ASP:TextBox id="user" runat="server"/></td>
</tr>
<tr>
<td><b>Password: </b></td>
<td><ASP:TextBox id="password" TextMode="Password" runat="server"/></td>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>

예제의 세 번째 부분에서는 Web Forms 페이지에서 사용자 컨트롤을 사용하는 LogOnControl 방법을 보여 줍니다.

<%@ Page Language="C#" Debug = "true"%>
<%@ Reference Control="Logonformcs.ascx" %>
<script language="C#" runat="server">

// The following example demonstrates how to load a user control dynamically at run time, and
// work with the ControlCachePolicy object associated with it.

// Loads and displays a UserControl defined in a seperate Logonform.ascx file.
// You need to have "Logonform.ascx" and "LogOnControl.cs" file in 
// the same directory as the aspx file. 

void Page_Init(object sender, System.EventArgs e) {
    
    // Obtain a PartialCachingControl object which wraps the 'LogOnControl' user control.
    PartialCachingControl pcc = LoadControl("Logonform.cs.ascx") as PartialCachingControl;        
    
    ControlCachePolicy cacheSettings = pcc.CachePolicy;
    
    // If the control is slated to expire in greater than 60 Seconds
    if (cacheSettings.Duration > TimeSpan.FromSeconds(60) ) {        
        
        // Make it expire faster. Set a new expiration time to 30 seconds, and make it
        // an absolute expiration if it isnt already.        
        cacheSettings.SetExpires(DateTime.Now.Add(TimeSpan.FromSeconds(30)));
        cacheSettings.SetSlidingExpiration(false);
    }                    
    Controls.Add(pcc);
}
</script>
<%@ Page Language="VB" Debug = "true"%>
<%@ Reference Control="Logonformvb.ascx" %>
<script language="VB" runat="server">
    ' The following example demonstrates how to load a user control dynamically at run time, and
    ' work with the ControlCachePolicy object associated with it.

    ' Loads and displays a UserControl defined in a seperate Logonform.ascx file.
    ' You need to have "Logonform.ascx" and "LogOnControl.vb" file in 
    ' the same directory as the aspx file.
    Sub Page_Init(ByVal Sender As Object, ByVal e As EventArgs)

        ' Obtain a PartialCachingControl object which wraps the 'LogOnControl' user control.
        Dim pcc As PartialCachingControl
        pcc = CType(LoadControl("Logonform.vb.ascx"), PartialCachingControl)
    
        Dim cacheSettings As ControlCachePolicy
        cacheSettings = pcc.CachePolicy
    
        ' If the control is slated to expire in greater than 60 Seconds
        If (cacheSettings.Duration > TimeSpan.FromSeconds(60)) Then
        
            ' Make it expire faster. Set a new expiration time to 30 seconds, and make it
            ' an absolute expiration if it isnt already.        
            cacheSettings.SetExpires(DateTime.Now.Add(TimeSpan.FromSeconds(30)))
            cacheSettings.SetSlidingExpiration(False)
        End If
        Controls.Add(pcc)

    End Sub ' Page_Init
              
</script>

설명

CachePolicy 속성을 사용하면 인스턴스에 ControlCachePolicy 포함된 BasePartialCachingControl 사용자 컨트롤과 연결된 개체에 프로그래밍 방식으로 액세스할 수 있습니다. ControlCachePolicy 사용자 컨트롤의 캐싱 동작 및 설정에 영향을 주도록 개체를 프로그래밍 방식으로 조작할 수 있습니다.

적용 대상

추가 정보