Adding OutPutCache to Control Definition Alters its Class ...?
<p>I'm working on a web app (CMS) that loads controls dynamically into a holder page. Using .Net version 3.5.</p>

<p>All my controls inherit from a custom base class.</p>

<p>So at runtime I have a bit of code that does something like this:</p>

<pre><code>Sarx.cms.BaseControl bctl = (Sarx.cms.BaseControl)LoadControl(sourceOfTheControl);
</code></pre>

<p>All was fine until I added an outputcache directive to the control definition (in the markup).</p>

<p>No, the above cast fails with an InvalidCastException.</p>

<p>I looked at the Control that is the output of the LoadControl and cast, and the runtime reports it is now of type PartialCachingControl:</p>

<pre><code>Control c1 = LoadControl(PageData.PageApplications[i].Source);
c1.GetType()
</code></pre>

<p>UnderlyingSystemType: {Name = "PartialCachingControl" FullName = "System.Web.UI.PartialCachingControl"}</p>

<p>I'd appreciate it if someone could explain and/or suggest a workaround.</p>

<p>Thanks in advance,</p>

<p>5arx</p>
