If you have two user controls (ascx) in the asp.net cache and need to update a user control if the other changes, you can use the following method:
On the dependent ascx, that needs to refresh:
PartialCachingControl pcc= Parent as PartialCachingControl;
StaticPartialCachingControl spcc= Parent as StaticPartialCachingControl;
if (pcc !=null) pcc.Dependency=new CacheDependency(null, new string[]{"HighLightChange"});
This will create a cache dependency on the HighLightChange string.
On the ascx that needs to invalidate the cache:
HttpRuntime.Cache.Insert("HighLightChange","true");
The change on the HighLightChange will invalidate the cache dependency of the user control that must do a data refresh.
No comments:
Post a Comment