usercontrol caching
-
Hi. I need to cache a usercontrol on a page. I have tried:
<%@ OutputCache Duration = "100" VaryByParam="none" %>
in the design of the UC. And it gives the OBJECT NOT SET TO AN INSTANCE... error on the container page when i try to reference the UC. I have also tried:Response.Cache.SetExpires(DateTime.Now.AddSeconds(100)); Response.Cache.SetCacheability(HttpCacheability.Public);
in the page load of the usercontrol. In the container page code i try:if (UCarticles1.CachePolicy.SupportsCaching) { UCarticles1.CachePolicy.Duration = new TimeSpan(0,0,20); }
But I get the value offalse
from theif
statement. Can someone help me please? What am I doing wrong? Thanks for your help.:-O -
Hi. I need to cache a usercontrol on a page. I have tried:
<%@ OutputCache Duration = "100" VaryByParam="none" %>
in the design of the UC. And it gives the OBJECT NOT SET TO AN INSTANCE... error on the container page when i try to reference the UC. I have also tried:Response.Cache.SetExpires(DateTime.Now.AddSeconds(100)); Response.Cache.SetCacheability(HttpCacheability.Public);
in the page load of the usercontrol. In the container page code i try:if (UCarticles1.CachePolicy.SupportsCaching) { UCarticles1.CachePolicy.Duration = new TimeSpan(0,0,20); }
But I get the value offalse
from theif
statement. Can someone help me please? What am I doing wrong? Thanks for your help.:-OHi, Caching in UserControls is called Fragment Caching. When u use Fragment Caching you can not perform any operation with the instance of that usercontrol in the container page's codebehind. and if u try to do so u will get NullReferenceException. I hope this will help you.
Thanks and Regards, Chetan Ranpariya
-
Hi, Caching in UserControls is called Fragment Caching. When u use Fragment Caching you can not perform any operation with the instance of that usercontrol in the container page's codebehind. and if u try to do so u will get NullReferenceException. I hope this will help you.
Thanks and Regards, Chetan Ranpariya
-
Hi, Your usercontrol itself is an example. You just remove caching feature from your user control and then try to run you application. I m sure u wont get exception at that time.
Thanks and Regards, Chetan Ranpariya
-
Hi, Your usercontrol itself is an example. You just remove caching feature from your user control and then try to run you application. I m sure u wont get exception at that time.
Thanks and Regards, Chetan Ranpariya
-
I NEED caching to run my app., hence I cannot remove the caching feature. I want the contents of the UC to be cached for 2 minutes and then afterwards, get the updated contents and display on container page and then cached again... Thanks
Hi, If its neccessary to user Caching in ur usercontrol then you should choose some other approach to implement the functionality that u want to implement by using reference of UC in the page codebehind.
Thanks and Regards, Chetan Ranpariya
-
Hi, If its neccessary to user Caching in ur usercontrol then you should choose some other approach to implement the functionality that u want to implement by using reference of UC in the page codebehind.
Thanks and Regards, Chetan Ranpariya
-
Hi. I need to cache a usercontrol on a page. I have tried:
<%@ OutputCache Duration = "100" VaryByParam="none" %>
in the design of the UC. And it gives the OBJECT NOT SET TO AN INSTANCE... error on the container page when i try to reference the UC. I have also tried:Response.Cache.SetExpires(DateTime.Now.AddSeconds(100)); Response.Cache.SetCacheability(HttpCacheability.Public);
in the page load of the usercontrol. In the container page code i try:if (UCarticles1.CachePolicy.SupportsCaching) { UCarticles1.CachePolicy.Duration = new TimeSpan(0,0,20); }
But I get the value offalse
from theif
statement. Can someone help me please? What am I doing wrong? Thanks for your help.:-OAdd the following element to the OutputCache directive for your usercontrol VaryByControl= name of the property by which u want to cache your control