We can cache dynamically loaded user controls using the following steps.
1. Include <%@ OutputCache %> directive in the user control that is in .ascx file.
2. When a user control is cached, ASP.Net framework wraps the user control as an instance of the PartialCachingControl class. Therefore we need to cast the control returned by the Page.LoadControl method as of PartialCachingControltype.Page.LoadControl () method is used for dynamically loading of user control.
3. User Control’s CachePolicy property supports Cached, Dependency, VaryByParams, VaryByControls, SetExpires, SetVaryByCustom, SetSlidingExpiration properties which we can use programmatically for caching of User Control.
4. Add the control to PlaceHolder control which acts as the container of controls.
Below is an example for caching a user control which is loading dynamically.