BasePartialCachingControl.CachePolicy Eigenschap

Definitie

Hiermee haalt u het ControlCachePolicy object op dat is gekoppeld aan het ingepakte gebruikersbeheer.

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

Waarde van eigenschap

Een ControlCachePolicy die uitvoereigenschappen in cache opslaat van het ingepakte gebruikersbesturingselement.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe een gebruikersbeheer dynamisch kan worden geladen en programmatisch kan worden gemanipuleerd tijdens runtime. In dit voorbeeld zijn drie delen:

  • Een gedeeltelijke klasse, LogOnControldie wordt overgenomen van de UserControl basisklasse en waarop het PartialCachingAttribute kenmerk wordt toegepast.

  • Een gebruikersbeheer dat wordt gebruikt met de LogOnControl gedeeltelijke klasse.

  • Een webpagina met webformulieren die als host fungeert voor het gebruikersbeheer.

Als u dit voorbeeld wilt uitvoeren, moet u ervoor zorgen dat het gebruikersbesturingselementbestand (.ascx), het bijbehorende code-behind-bestand (.cs of .vb) en de webpagina met webformulieren die als host fungeert voor het gebruikersbesturingselement (.aspx) zich in dezelfde map bevinden.

Het eerste deel van het voorbeeld laat zien hoe het PartialCachingAttribute wordt toegepast op een gebruikersbeheer met de naam LogOnControl, wat betekent dat het gebruikersbeheer tijdens runtime wordt verpakt door een PartialCachingControl besturingselement. De cache-instellingen van het LogOnControl object kunnen programmatisch worden bewerkt via het bijbehorende ControlCachePolicy object, dat beschikbaar is via een verwijzing naar de PartialCachingControl inhoud ervan. In dit voorbeeld worden cache-instellingen onderzocht tijdens de initialisatie van pagina's en gewijzigd als aan bepaalde voorwaarden wordt voldaan.

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

In het tweede deel van het voorbeeld ziet u een gebruikersbeheer dat in het vorige voorbeeld wordt gebruikt om caching van gebruikersbeheer te demonstreren.

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

Het derde deel van het voorbeeld laat zien hoe u het LogOnControl gebruikersbeheer gebruikt vanaf een webpagina met webformulieren.

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

Opmerkingen

De CachePolicy eigenschap maakt programmatische toegang mogelijk tot het ControlCachePolicy object dat is gekoppeld aan het gebruikersbesturingselement dat is opgenomen in het BasePartialCachingControl exemplaar. Het ControlCachePolicy object kan programmatisch worden bewerkt om het cachegedrag en de instellingen van een gebruikersbeheer te beïnvloeden.

Van toepassing op

Zie ook