Export (0) Print
Expand All

How to: Cache Multiple Versions of a User Control by Using Declarative Attributes 

You can cache multiple versions of a user control by simply declaring it in an .aspx file more than once. As with user controls that are not cached, you can include a cached user control in an ASP.NET page as many times as needed for your application. Unless you set the Shared property to true for the user control, multiple versions of the control output will be stored in the cache.

To cache multiple versions of a user control by using declarative attributes

  1. Using either the @ OutputCache directive in an .ascx file or the PartialCachingAttribute in the code-behind class, specify the output cache settings for the user control.

    The following @ OutputCache declaration will cache the control for 120 seconds:

    <%@ OutputCache Duration="120" VaryByParam="None" %>
    
  2. Include multiple versions of the user control in a page, including the property you defined in the class as an attribute in the element. Make sure the property values are unique on the page.

    Simply including the @ OutputCache directive with a valid duration value in the .ascx file or setting the PartialCachingAttribute in the code-behind class allows varied cache output of a user control.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft