If a user control (.ascx file) contains an @ OutputCache directive, Microsoft ASP.NET automatically generates a PartialCachingControl class when the user control is requested. The PartialCachingControl class contains a CachedControl property (the PartialCachingControl.CachedControl property). You can use the CachedControl property to determine if the control was pulled from the cache or if the control was newly constructed. If the value of this property is a null reference (Nothing in Microsoft Visual Basic), the user control was pulled from the cache. �If the value of this property is not a null reference, the user control was constructed. However, if the CachedControl is not coded correctly, the CachedControl property will always return a null reference. The CachedControl property always returns a null reference unless the control has been pre-added to the control tree. Before you check the CachedControl property, add the user control to the control tree. Note the code sample that is in the "More Information" section of this article.
Note This behavior is by design. The cached control is not created until the Init phase. The control is not created until you insert the PartialCachingControl class in the control tree.
For more information, see a code sample in the "More Information" section of this article.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.