Substitution.MethodName 屬性

定義

取得或設定 Substitution 控制項執行時要叫用的回呼方法名稱。

public:
 virtual property System::String ^ MethodName { System::String ^ get(); void set(System::String ^ value); };
public virtual string MethodName { get; set; }
member this.MethodName : string with get, set
Public Overridable Property MethodName As String

屬性值

String

字串,表示 Substitution 控制項執行時要叫用的方法名稱。

範例

下列程式碼範例示範如何以宣告方式將控制項新增 Substitution 至輸出快取的網頁。 頁面載入時,會將靜態項目符號清單顯示給使用者。 頁面的這個區段只會快取並每隔 60 秒更新一次。 Substitution當控制項執行時,它會呼叫 GetUser 方法,這個方法會傳回代表目前使用者的字串。 這個字串會顯示在頁面上控制項的位置 Substitution 。 頁面的這個區段不會快取,而且會在每次重新整理頁面時更新。

<%@ 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#">  
  
  // The Substitution control calls this method to retrieve
  // the name of the current user from the HttpContext object. 
  // This section of the page is exempt from output caching. 
  public static string GetUser(HttpContext context)
  {
    return context.User.Identity.Name;
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution.MethodName Property Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution.MethodName Property Example</h3>  
    
    <!--This section of the page is not cached.-->
    Welcome to the site,
    <asp:substitution id="Substitution1"
      methodname="GetUser"
      runat="Server">
    </asp:substitution>
    
    <br /><br />
    
    <!--This section of the page is cached.-->
    Product list:
    <asp:bulletedlist id="ItemsBulletedList"             
      displaymode="Text" 
      runat="server">    
        <asp:ListItem>Product 1</asp:ListItem>
        <asp:ListItem>Product 2</asp:ListItem>
        <asp:ListItem>Product 3</asp:ListItem>
    </asp:bulletedlist>        

  </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="VB">  
  
  ' The Substitution control calls this method to retrieve
  ' the name of the current user from the HttpContext object. 
  ' This section of the page is exempt from output caching. 
  Shared Function GetUser(ByVal context As HttpContext) As String
    Return context.User.Identity.Name
  End Function
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution.MethodName Property Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution.MethodName Property Example</h3>  
    
    <!--This section of the page is not cached.-->
    Welcome to the site,
    <asp:substitution id="Substitution1"
      methodname="GetUser"
      runat="Server">
    </asp:substitution>
    
    <br /><br />
    
    <!--This section of the page is cached.-->
    Product list:
    <asp:bulletedlist id="ItemsBulletedList"             
      displaymode="Text" 
      runat="server">    
        <asp:ListItem>Product 1</asp:ListItem>
        <asp:ListItem>Product 2</asp:ListItem>
        <asp:ListItem>Product 3</asp:ListItem>
    </asp:bulletedlist>        

  </form>
</body>
</html>

備註

MethodName使用 屬性可指定要在控制項執行時叫用的 Substitution 回呼方法名稱。 您指定的回呼方法必須是包含控制項的頁面或使用者控制項 Substitution 上的靜態方法。 回呼方法的簽章必須符合接受 HttpContext 參數並傳回字串之委派的簽章 HttpResponseSubstitutionCallback 。 回呼方法傳回的字串是顯示在控制項位置 Substitution 頁面上的內容。

參數 HttpContext 會封裝個別 HTTP 要求的所有 HTTP 特定資訊。 您可以使用它來存取會話變數、授權資訊和個人化詳細資料。 如需詳細資訊,請參閱HttpResponseSubstitutionCallback

適用於

另請參閱