UserControl.CachePolicy Propriété

Définition

Obtient une référence à une collection de paramètres de mise en cache pour ce contrôle utilisateur.

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

Valeur de propriété

ControlCachePolicy

ControlCachePolicy contenant des propriétés qui définissent les paramètres de mise en cache pour ce UserControl.

Attributs

Exemples

L’exemple de code suivant montre comment utiliser la SupportsCaching propriété pour déterminer si le contrôle utilisateur peut être mis en cache et, le cas échéant, définit la Duration propriété pour mettre en cache le contrôle pendant 10 secondes.

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

Remarques

La CachePolicy propriété définit les paramètres de cache pour l’instance de la UserControl classe. La CachePolicy propriété est en lecture seule. Toutefois, vous pouvez définir les propriétés de l’objet ControlCachePolicy qu’elle retourne.

La CachePolicy propriété ne peut pas être définie de manière déclarative. Elle doit être définie par programmation.

S’applique à

Voir aussi