Substitution.Substitution Constructor

Initializes a new instance of the Substitution class.

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

public Substitution ()
public Substitution ()
public function Substitution ()
Not applicable.

Use the Substitution constructor to create and initialize a new instance of the Substitution class.

The following code example demonstrates how to add a Substitution control programmatically to an output-cached Web page. When the page loads, the current date and time are displayed to the user in a label. This section of the page is cached and updated only every 60 seconds. When the Substitution control executes, it calls the GetCurrentDateTime method. The string returned by GetCurrentDateTime is displayed to the user. 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#">  
  void Page_Load(object sender, System.EventArgs e)
    // Programmatically create a Substitution control.
    Substitution Substitution1 = new Substitution();
    // Specify the callback method.
    Substitution1.MethodName = "GetCurrentDateTime";
    // Add the Substitution control to the controls
    // collection of PlaceHolder1.
    PlaceHolder1.Controls.Add (Substitution1);        

    // 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 ();

<html xmlns="" >
<head id="Head1" runat="server">
  <title>Substitution Class Example</title>
  <form id="Form1" runat="server">
    <h3>Substitution Constructor Example</h3>  
    <p>This section of the page is not cached:</p>
    <asp:placeholder id="PlaceHolder1"
    <br />
    <p>This section of the page is cached:</p>
    <asp:label id="CachedDateLabel"
    <br /><br />
    <asp:button id="RefreshButton"
      text="Refresh Page"


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