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,包含为该 UserControl 定义缓存参数的属性。

属性

示例

下面的代码示例演示如何使用 SupportsCaching 属性来确定用户控件是否可以缓存,如果是,则将 属性设置为 Duration 缓存控件 10 秒。

<%@ 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无法以声明方式设置 属性。 必须以编程方式设置它。

适用于

另请参阅