Substitution control: outputs the cache status on the page to maintain dynamic updates of some data.

Source: Internet
Author: User
<% @ 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 >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.