This documentation is archived and is not being maintained.

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; }
<asp:Substitution MethodName="String" />

Property Value

Type: System.String
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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0