UserControl.CachePolicy プロパティ

定義

このユーザー コントロールのキャッシュ パラメーターのコレクションへの参照を取得します。

public:
 property System::Web::UI::ControlCachePolicy ^ CachePolicy { System::Web::UI::ControlCachePolicy ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.ControlCachePolicy CachePolicy { get; }
[<System.ComponentModel.Browsable(false)>]
member this.CachePolicy : System.Web.UI.ControlCachePolicy
Public ReadOnly Property CachePolicy As ControlCachePolicy

プロパティ値

ControlCachePolicy

この ControlCachePolicy のキャッシュ パラメーターを定義するプロパティを格納している UserControl

属性

次のコード例は、プロパティを SupportsCaching 使用してユーザー コントロールをキャッシュできるかどうかを判断する方法を示しています。その場合は、コントロールを 10 秒間キャッシュするようにプロパティを設定 Duration します。

<%@ page language="C#"%>
<%@ register src="SimpleControlcs.ascx" 
             tagname="SimpleControl" 
             tagprefix="uc1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Init(object sender, EventArgs e)
{
  // If the control is already in the cache, calling properties
  // will throw an exception. Make sure the control is available. 
  if (SimpleControl1 != null)
  {
    
    Page.DataBind();
    
    if (SimpleControl1.CachePolicy.SupportsCaching)
    {
      // Set the cache duration to 10 seconds.
      SimpleControl1.CachePolicy.Duration = new TimeSpan(0, 0, 10);
      
    }
  }
}

</script>
<%@ page language="VB"%>
<%@ register src="SimpleControlvb.ascx" 
             tagname="SimpleControl" 
             tagprefix="uc1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    If SimpleControl1 IsNot Nothing Then

      Page.DataBind()
      
      If SimpleControl1.CachePolicy.SupportsCaching Then

        ' Set the cache duration to 10 seconds.

        SimpleControl1.CachePolicy.Duration = New TimeSpan(0, 0, 10)

      End If

    End If

  End Sub
</script>

注釈

このプロパティは CachePolicy 、クラスのインスタンスのキャッシュ パラメーターを UserControl 定義します。 プロパティは CachePolicy 読み取り専用です。ただし、返されるオブジェクトのプロパティを ControlCachePolicy 設定できます。

このプロパティは CachePolicy 宣言によって設定できません。 プログラムで設定する必要があります。

適用対象

こちらもご覧ください