Substitution コンストラクタ
アセンブリ: System.Web (system.web.dll 内)



Substitution コントロールを出力キャッシュを使用する Web ページにプログラムによって追加する方法のコード例を次に示します。ページが読み込まれると、ユーザーに対して現在の日付と時刻がラベルに表示されます。ページのこのセクションはキャッシュされ、60 秒ごとに更新されます。Substitution コントロールは、実行時に GetCurrentDateTime メソッドを呼び出します。GetCurrentDateTime から返される文字列がユーザーに表示されます。ページのこのセクションはキャッシュされず、ページの表示が更新されるたびに更新されます。
<%@ outputcache duration="60" varybyparam="none" %> <script runat="server" language="VB"> Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' Programmatically create a Substitution control. Dim Substitution1 As New Substitution ' Specify the callback method. Substitution1.MethodName = "GetCurrentDateTime" ' Add the Substitution control to the controls ' collection of PlaceHolder1. PlaceHolder1.Controls.Add(Substitution1) ' Display the current date and time in the label. ' Output caching applies to this section of the page. CachedDateLabel.Text = DateTime.Now.ToString() End Sub ' The Substitution control calls this method to retrieve ' the current date and time. This section of the page ' is exempt from output caching. Shared Function GetCurrentDateTime(ByVal context As HttpContext) As String Return DateTime.Now.ToString() End Function </script> <html> <head id="Head1" runat="server"> <title>Substitution Constructor Example</title> </head> <body> <form id="Form1" runat="server"> <h3>Substitution Constructor Example</h3> <p>This section of the page is not cached:</p> <asp:placeholder id="PlaceHolder1" runat="Server"> </asp:placeholder> <br /> <p>This section of the page is cached:</p> <asp:label id="CachedDateLabel" runat="Server"> </asp:label> <br /><br /> <asp:button id="RefreshButton" text="Refresh Page" runat="Server"> </asp:button> </form> </body> </html>
<%@ outputcache duration="60" varybyparam="none" %> <script runat="server" language="C#"> void Page_Load(object sender, System.EventArgs e) { // Programmatically create a Substitution control. Substitution Substitution1 = new Substitution(); // Specify the callback method. Substitution1.MethodName = "GetCurrentDateTime"; // Add the Substitution control to the controls // collection of PlaceHolder1. PlaceHolder1.Controls.Add (Substitution1); // Display the current date and time in the label. // Output caching applies to this section of the page. CachedDateLabel.Text = DateTime.Now.ToString(); } // The Substitution control calls this method to retrieve // the current date and time. This section of the page // is exempt from output caching. public static string GetCurrentDateTime (HttpContext context) { return DateTime.Now.ToString (); } </script> <html> <head id="Head1" runat="server"> <title>Substitution Class Example</title> </head> <body> <form id="Form1" runat="server"> <h3>Substitution Constructor Example</h3> <p>This section of the page is not cached:</p> <asp:placeholder id="PlaceHolder1" runat="Server"> </asp:placeholder> <br /> <p>This section of the page is cached:</p> <asp:label id="CachedDateLabel" runat="Server"> </asp:label> <br /><br /> <asp:button id="RefreshButton" text="Refresh Page" runat="Server"> </asp:button> </form> </body> </html>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Substitution クラス
Substitution メンバ
System.Web.UI.WebControls 名前空間
その他の技術情報
Substitution Web サーバー コントロール
- Substitution コンストラクタのページへのリンク