<% @ Page Language = " C # " %>
<!Doctype HTML public"-// W3C // dtd xhtml 1.0 transitional // en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Script runat="Server">
Protected Void Page_load ( Object Sender, eventargs E)
{
// Cache the entire page, with the same effect as the page output Cache
// <% @ Outputcache duration = "60" varybyparam = "NONE" %>
Response. cache. setexpires (datetime. Now. addseconds ( 40 ));
Response. cache. setcacheability (httpcacheability. Public );
// Response. cache. setvaliduntilexpires (true );
}
Private Static StringGettime (httpcontext context)
{
ReturnDatetime. Now. tostring ();
}
</Script>
< HTML xmlns = " Http://www.w3.org/1999/xhtml " >
< Head runat = " Server " >
< Title > Untitled page </ Title >
</ Head >
< Body >
< Form ID = " Form1 " Runat = " Server " >
< Div >
The substitution control refreshes part of the cached page to maintain dynamic updates of some data.. < BR />
This time will be cached: <% = Datetime. Now. tostring () %> < BR />
Although the entire page is cached, the following time does not exist, because we use the substitution control. < BR />
Current Time:
< SPAN Style = " Color: red; font-weight: bold; " > < ASP: substitution ID = " Subtime " Runat = " Server " Methodname = " Gettime " /> </ Span > < BR />
Attributes of the substitution Control < I > < B > Methodname </ B > </ I > Specify a tape < I > < B > HttpcontextParameters </ B > </ I > Of < I > < B > Static Method </ B > </ I > , < BR />
The returned data is displayed in the control. < BR />
< SPAN Style = " Color: blue; " > Private < B > Static </ B > String Gettime ( < B > Httpcontext </ B > Context) </ Span >
< BR />
</ Div >
</ Form >
</ Body >
</ Html >