views:

120

answers:

1

The problem: I am unable to use OutputCaching with my controls which derives from MyCustomControl. Controls are loaded dynamically using definitions from database with Page.LoadControl method.

When I add to ascx <%@ OutputCache VaryByParam="*" Duration="3600"%> the "InvalidCastException: System.Web.UI.PartialCachingControl -> MyCustomControl" exception is thrown.

I am unable to modify assembly witch contains dynamic loading controls logic. Is there any way to fix it in derived controls?

The second question is about iis7 and native output caching - is it resolves this problem? (I tried to set up several performance counters and I saw that cache wasn't hit...)

A: 

If you are loading the controls dynamically they are loaded as System.Web.UI.PartialCachingControl.

Control control = Page.LoadControl("/somecontrol.ascx");
this.Controls.Add(control);
MyCustomControl myControl = ((PartialCachingControl)control).CachedControl as MyCustomControl 

This behaviour is exacty the same in IIS7

jonot