Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
UserControl Class
 CachePolicy Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
UserControl..::.CachePolicy Property

Updated: November 2007

Gets a reference to a collection of caching parameters for this user control.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

Visual Basic (Declaration)
<BrowsableAttribute(False)> _
Public ReadOnly Property CachePolicy As ControlCachePolicy
Visual Basic (Usage)
Dim instance As UserControl
Dim value As ControlCachePolicy

value = instance.CachePolicy
C#
[BrowsableAttribute(false)]
public ControlCachePolicy CachePolicy { get; }
Visual C++
[BrowsableAttribute(false)]
public:
property ControlCachePolicy^ CachePolicy {
    ControlCachePolicy^ get ();
}
J#
/** @property */
/** @attribute BrowsableAttribute(false) */
public ControlCachePolicy get_CachePolicy()
JScript
public function get CachePolicy () : ControlCachePolicy

Property Value

Type: System.Web.UI..::.ControlCachePolicy

A ControlCachePolicy containing properties that define the caching parameters for this UserControl.

The CachePolicy property defines the cache parameters for the instance of the UserControl class. The CachePolicy property is read-only; however, you can set the properties of the ControlCachePolicy object that it returns.

The CachePolicy property can not be set declaratively. It must be set programmatically.

The following code example demonstrates how to use the SupportsCaching property to determine whether the user control can be cached, and if so, sets the Duration property to cache the control for 10 seconds.

Visual Basic
<%@ 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>

C#
<%@ 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>

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker