OutputCache dynamically loaded UserControl.
-
Dear CPians, I am trying to enable OutpoutCache on a UserControl which is dynamically added to the page. I get an exception when I instantiate the UserControl. The code goes as follows:
DisplayTime myUserControl; myUserControl = (DisplayTime)LoadControl("DisplayTime.ascx");
If I do not have an OutputCache directive it works fine. When I add the following:<%@ OutputCache Duration="20" VaryByParam="*" Shared="true" %>
I get the following exception:System.InvalidCastException: Unable to cast object of type 'System.Web.UI.PartialCachingControl' to type 'TestApp.DisplayTime'.
Any Ideas?Excellence is not an act, but a habit!
Aristotle
-
Dear CPians, I am trying to enable OutpoutCache on a UserControl which is dynamically added to the page. I get an exception when I instantiate the UserControl. The code goes as follows:
DisplayTime myUserControl; myUserControl = (DisplayTime)LoadControl("DisplayTime.ascx");
If I do not have an OutputCache directive it works fine. When I add the following:<%@ OutputCache Duration="20" VaryByParam="*" Shared="true" %>
I get the following exception:System.InvalidCastException: Unable to cast object of type 'System.Web.UI.PartialCachingControl' to type 'TestApp.DisplayTime'.
Any Ideas?Excellence is not an act, but a habit!
Aristotle
Well, sometimes it is worth to ask google before posting anything here :) search for "Unable to cast object of type ‘System.Web.UI.PartialCachingControl’" and first link will be this: http://msdn.microsoft.com/msdnmag/issues/06/07/WebAppFollies/default.aspx Pilo