指定输出缓存的网页中不进行缓存的部分。在此位置,将检索动态内容,并用它们替代 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 控件。加载页时,在标签中向用户显示当前的日期和时间。每 60 秒缓存并更新页的此部分。当 Substitution 控件执行时,它调用 GetCurrentDateTime 方法。GetCurrentDateTime 返回的字符串显示给用户。页的此部分不进行缓存,而是在每次刷新页时进行更新。
        
      
      | Visual Basic? |  复制代码 | 
|---|
<%@ outputcache duration="60" varybyparam="none" %>
<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>
<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>
 | 
| C#? |  复制代码 | 
|---|
<%@ outputcache duration="60" varybyparam="none" %>
<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>
<head runat="server">
  <title>Substitution Class Example</title>
</head>
<body>
  <form 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
概念
Substitution Web 服务器控件概述