Substitution class (Asp.net 2.0)

Source: Internet
Author: User

UseSubstitutionControl specifies that the portion of the control must be replaced with dynamic content on the output cache webpage.SubstitutionControls provide a simplified solution for caching partial pages for pages that require most of the content to be cached. You can cache the output of the entire page and then useSubstitutionControl specifies the part on the page that is exempt from caching. The region to be cached is executed only once, and then read from the cache until the cache entry expires or is cleared. The dynamic region is executed on each request page. Because you do not have to encapsulate these parts to cache them in Web user controls, this cache model simplifies the pages that are mainly static content.Code. For example, if a page contains static content (such as news reports) and adrotator controls that display advertisements, this cache model is useful. News reports will not be changed, which means they can be cached. However, you want to display a new advertisement each time the user requests this page.AdrotatorThe control can be replaced after caching. Whether or not the page is cached, a new advertisement is displayed when the page is sent back.

Note:

You can placeSubstitutionControl. However, it cannot be placed in the output cache user control.SubstitutionControl.

SubstitutionWhen the control is executed, a method to return a string is called. The string returned by this method isSubstitutionThe position of the widget. Use the methodname attribute to specifySubstitutionThe name of the callback method called when the control is executed. The specified callback method must containSubstitutionControl page or user control static method. The signature of the callback method must be accepted. Parameter and returns the string The signature of the delegate.

To operate the output cache of the page, you can use Commands, Class or Attribute. For more information about the cache page, see And .

SubstitutionAnother way to use the control is to useHttpresponsesubstitutioncallbackDelegate to implement cache replacement. In addition, you can directly support the cache replacement function controls (suchAdrotatorControl. For more information, see .

Example:

<% @ Outputcache duration = "60" varybyparam = "NONE" %> <SCRIPT runat = "server" Language = "C #"> void page_load (Object sender, system. eventargs e) {// display the current date and time in the label. // output caching applies to this section of the page. cacheddatelabel. TEXT = datetime. now. tostring ();} // The substitution control callthis method to retrieve // the current date and time. this section of the page // is exempt from output caching. public static string getcurrentdatetime (httpcontext context) {return datetime. now. tostring ();} </SCRIPT> <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.