BasePartialCachingControl.CachePolicy プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As BasePartialCachingControl Dim value As ControlCachePolicy value = instance.CachePolicy
ラップされたユーザー コントロールのキャッシュ関連のプロパティを格納する ControlCachePolicy。

CachePolicy プロパティを使用すると、BasePartialCachingControl インスタンスで格納されたユーザー コントロールに関連付けられている ControlCachePolicy オブジェクトにプログラムからアクセスできます。ControlCachePolicy オブジェクトは、ユーザー コントロールの動作や設定に影響を与えるためにプログラムから操作できます。

実行時にプログラムからユーザー コントロールを動的に読み込み、操作する方法を次のコード例に示します。この例は、3 つの部分で構成されます。
-
UserControl 基本クラスから継承し、PartialCachingAttribute 属性の適用先となる部分クラス LogOnControl。
-
LogOnControl 部分クラスで使用するユーザー コントロール。
この例を正常に実行するには、ユーザー コントロール ファイル (.ascx)、それに対応する分離コード ファイル (.cs または .vb)、およびそのユーザー コントロール (.aspx) をホストする Web フォーム ページが同じディレクトリ内にあることを確認してください。
この例の最初の部分では、PartialCachingAttribute を LogOnControl という名前のユーザー コントロールに適用する方法を示しています。これは、ユーザー コントロールが実行時に PartialCachingControl コントロールによってラップされることを意味します。LogOnControl オブジェクトのキャッシュ設定は、関連付けられた ControlCachePolicy オブジェクト (このオブジェクトをラップする PartialCachingControl への参照を使用してアクセス可能) を通じてプログラムから操作できます。この例では、ページの初期化中にキャッシュ設定がチェックされ、条件が満たされた場合は変更されます。
Imports System 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 'LogOnControl
using System; using System.Web.UI; using System.Web.UI.WebControls; [PartialCaching(100)] public class LogOnControl:UserControl { public TextBox user; public TextBox password; }
この例の 2 番目の部分には、前述の例でユーザー コントロールのキャッシュ方法を示すために使用するユーザー コントロールを示しています。
<%@ control inherits = "LogOnControl" src = "LogOnControl.vb" %> <form 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>
<%@ control inherits = "LogOnControl" src = "LogOnControl.cs" %> <form 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>
この例の 3 番目の部分では、Web フォーム ページから LogOnControl ユーザー コントロールを使用する方法を示しています。
<%@ 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>
<%@ 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBasePartialCachingControl.CachePolicy プロパティを検索する場合は、下記のリンクをクリックしてください。

- BasePartialCachingControl.CachePolicy プロパティのページへのリンク