Substitution Web サーバー コントロールの宣言構文
更新 : 2007 年 11 月
キャッシュから除外される出力キャッシュ Web ページ上のセクションを指定します。この領域では、動的コンテンツが取得され、Substitution コントロールの代わりに配置されます。
<asp:Substitution
EnableTheming="True|False"
EnableViewState="True|False"
ID="string"
MethodName="string"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
runat="server"
SkinID="string"
Visible="True|False"
/>
解説
Substitution コントロールは、出力キャッシュ Web ページ上に動的コンテンツを配置する領域を指定するために使用します。このとき、このコントロールの場所に動的コンテンツが配置されます。Substitution コントロールは、ほとんどのコンテンツがキャッシュされるページの部分ページ キャッシュに対して、合理的な解決策を提供します。まずページ全体を出力キャッシュし、その後 Substitution コントロールを使用して、キャッシュから除外するページの部分を指定できます。
Substitution コントロールの詳細については、「Substitution Web サーバー コントロールの概要」を参照してください。
使用例
出力キャッシュ Web ページに、Substitution コントロールを宣言的に追加する方法を、次のコード例に示します。ページが読み込まれると、現在の日付と時間がラベル内に表示されます。ページのこのセクションはキャッシュされ、60 秒ごとに更新されます。Substitution コントロールが実行されると、GetCurrentDateTime メソッドが呼び出されます。この GetCurrentDateTime によって返された文字列がユーザーに表示されます。ページのこのセクションはキャッシュされず、ページが更新されるたびに更新されます。
<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="VB">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' 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 xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Substitution Class Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>Substitution Class Example</h3>
<p>This section of the page is not cached:</p>
<asp:substitution id="Substitution1"
methodname="GetCurrentDateTime"
runat="Server">
</asp:substitution>
<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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="C#">
void Page_Load(object sender, System.EventArgs e)
{
// 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 xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Substitution Class Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Substitution Class Example</h3>
<p>This section of the page is not cached:</p>
<asp:substitution id="Substitution1"
methodname="GetCurrentDateTime"
runat="Server">
</asp:substitution>
<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>
参照
概念
Substitution Web サーバー コントロールの概要