ARTICLE

Substitution Control in ASP.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET December 01, 2010
In this article we will learn how to use Substitution control in ASP.NET.
 
Reader Level:

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.

s1.gif

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.

s2.gif

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html>

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

    <title>Post Cache Substitution</title>

</head>

<body>

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

        <h4>

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

        <p>

            DateTime using cheched:

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

        </p>

        <p>

            <b>DateTime using Substitution:

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

            </b>

        </p>

    </form>

</body>

</html>


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.

s3.gif

Figure 3.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor