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