File 1: deafault. aspx
CopyCode The Code is as follows: <% @ page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<% @ Outputcache duration = "10" varybyparam = "NONE" %>
<! -- Set the cache time to 10 seconds -->
<! 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> substitution control instance </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<H1> substitution control instance demonstration Hello <B>
<Asp: substitution id = "M1" methodname = "getuser" runat = "server">
</ASP: substitution> </B> <br>
Current time [non-Cache]:
<B> <asp: substitution id = "m2" runat = "server" methodname = "gettime"/> </B>
<Br/>
Cache: <% = datetime. Now. tolongtimestring () %>
<Asp: button id = "button1" runat = "server" text = "refresh"/>
</Form>
</Body>
</Html>
File 2: deafault. aspx. CSCopy codeThe Code is as follows: using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class _ default: system. Web. UI. Page
{
// The following two statement methods are defined. You can use the substitution control to call these two methods each time they are refreshed.
Public static string getuser (httpcontext context)
{
Return context. User. Identity. Name;
}
Public static string gettime (httpcontext context)
{
Return datetime. Now. tostring ();
}
}