Substitution Control in ASP.NET

In this article we will learn how to use Substitution control in ASP.NET.
  • 4104

In this article we will learn how to use Substitution control in ASP.NET.

Substitution control

Substitution control is used to call a method that returns a string in an output-cached page.

Properties:  The main property of the Substitution control is MethodName.


Figure 1.

MethodName - MethodName are Used to assign method name that will fire each time page will load and return the string. Please note that this method will be a static method.

For example: The below figure shows the Substitution control.


Figure 2.

Now click on the source button of the design form.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication34.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">


<head id="Head1" runat="server">

    <title>Post Cache Substitution</title>



    <form id="form1" runat="server">


            This page uses post cache substitution to insert a dynamic value into a cached page.</h4>


            DateTime using cheched:

            <%= DateTime.Now.ToString() %>



            <b>DateTime using Substitution:

                <asp:Substitution ID="Substitution1" runat="server" MethodName="GetCurrentDate" />







Now double click on the form and create a method GetCurrentDate calling through the MethodName property.

Shared Function GetCurrentDate(ByVal context As HttpContext) As String

        Return Now.ToString()

    End Function

Now save and run the application.


Figure 3.


More Articles

© 2020 DotNetHeaven. All rights reserved.