Search
Author
ASP.NET Tutorials
Author
Sheo Narayan
Advertisements


Winners

Win Prizes

Social Presence
Like us on Facebook

Silverlight Tutorials | Report a Bug in the Tutorial
asp:Substitution control
Substitution control is used to call a method that returns a string in an output-cached page.
 
Ideally Substitution control is used to call a method that returns a string in an output-cached page. Generally it is used when you want to cache a page but still want to return a dynamic string at a paricular part of the page.

There is one property that is used to return the dynamic string
MethodName 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.
DEMO : Substitution Show Source Code
DateTime using Substitution: 12/6/2024 2:24:48 PM DateTime using Cachced: 12/6/2024 2:24:48 PM

Notice that Cahced datetime will not change while Substituted datetime will change after each page refresh.
// Substitution Control /////////////////////////////////////////
<asp:Substitution ID="Substitution1" runat="server" MethodName="WriteCurrentTimeDespiteThePageIsCahced" />

 // Code Behind /////////////////////////////////////////
 protected static string WriteCurrentTimeDespiteThePageIsCahced(HttpContext context)
    {
        return DateTime.Now.ToString();
    }