Substitution.MethodName Propriedade

Definição

Recebe ou define o nome do método de callback para invocar quando o Substitution controlo é executado.

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

Valor de Propriedade

Uma cadeia que representa o nome do método a invocar quando o Substitution controlo é executado.

Exemplos

O exemplo de código seguinte demonstra como adicionar declarativamente um Substitution controlo a uma página Web com cache de saída. Quando a página carrega, é apresentada ao utilizador uma lista estática com tópicos. Esta secção da página é armazenada em cache e atualizada apenas a cada 60 segundos. Quando o Substitution controlo é executado, chama o GetUser método, que devolve uma string que representa o utilizador atual. Esta cadeia é exibida na localização do Substitution controlo na página. Esta secção da página não está em cache e é atualizada sempre que a página é atualizada.

<%@ 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>

Observações

Use a MethodName propriedade para especificar o nome do método de callback a invocar quando o Substitution controlo for executado. O método de callback que especifica deve ser um método estático na página ou controlo de utilizador que contém o Substitution controlo. A assinatura do método de callback deve corresponder à assinatura de um HttpResponseSubstitutionCallback delegado que pega num HttpContext parâmetro e devolve uma string. A string que o método de callback devolve é o conteúdo a ser exibido na página no local do Substitution controlo.

O HttpContext parâmetro encapsula toda a informação específica de HTTP sobre um pedido HTTP individual. Pode usá-lo para aceder a variáveis de sessão, informações de autorização e detalhes de personalização. Para obter mais informações, veja HttpResponseSubstitutionCallback.

Aplica-se a

Ver também