Substitution.MethodName Property

Gets or sets the name of the callback method to invoke when the Substitution control executes.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual string MethodName { get; set; }
/** @property */
public String get_MethodName ()

/** @property */
public void set_MethodName (String value)

public function get MethodName () : String

public function set MethodName (value : String)

Not applicable.

Property Value

A string that represents the name of the method to invoke when the Substitution control executes.

Use the MethodName property to specify the name of the callback method to invoke when the Substitution control executes. The callback method that you specify must be a static method on the page or user control that contains the Substitution control. The signature for the callback method must match the signature for a HttpResponseSubstitutionCallback delegate that takes an HttpContext parameter and returns a string. The string that the callback method returns is the content to display on the page at the location of the Substitution control.

The HttpContext parameter encapsulates all HTTP-specific information about an individual HTTP request. You can use it to access session variables, authorization information, and personalization details. For more information, see HttpResponseSubstitutionCallback.

The following code example demonstrates how to add a Substitution control declaratively to an output-cached Web page. When the page loads, a static bulleted list is displayed to the user. This section of the page is cached and updated only every 60 seconds. When the Substitution control executes, it calls the GetUser method, which returns a string that represents the current user. This string is displayed at the location of the Substitution control on the page. This section of the page is not cached and is updated each time the page is refreshed.

<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<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;

<html xmlns="" >
<head id="Head1" runat="server">
  <title>Substitution.MethodName Property Example</title>
  <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"
    <br /><br />
    <!--This section of the page is cached.-->
    Product list:
    <asp:bulletedlist id="ItemsBulletedList"             
        <asp:ListItem>Product 1</asp:ListItem>
        <asp:ListItem>Product 2</asp:ListItem>
        <asp:ListItem>Product 3</asp:ListItem>


Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions