Hi
I am having some problem, trying to cache a user control in my application(am using ASP.Net2.0).
Here is a description of the user control

1. The user control is visible for most of the pages in my application.
2. It comes in only two versions. Initially one version is shown in all the pages(no problem until now with the caching). But once the user performs a certain activity(selecting certain items and clicking on 'ok') .. the second version will be visible to the user on all the pages from then on.
3. Seems like I have to refresh the usercontrol in the cache when the user does his thing. But how?

Thanks in advance

Hi

I read somewhere that you can create a dependency on the wrapper class for some cache key and delete the key when you want to refresh the control in the cache.. so I wrote a small application to try out the idea... here the usercontrol is cached indefinitely but once I click on a button in the page it is supposed to get refreshed.. however its not happening.. cant understand the reason...heres the code

default.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Cache.Item("CacheRemovalKey") Is Nothing) Then
Cache.Insert("CacheRemovalKey", "Key", Nothing, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration) Dim pcc As PartialCachingControl = CType(LoadControl("UserControlEx.ascx"), PartialCachingControl) Dim DependentKeyArray As String() = {"CacheRemovalKey"} pcc.Dependency = New System.Web.Caching.CacheDependency(Nothing, DependentKeyArray)
End If
End Sub

Protected Sub btnChange_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChange.Click
Cache.Remove("CacheRemovalKey")
End Sub

UserControl.ascx.vb

Partial Class UserControlEx Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtDateTime.Text = Date.Now
End Sub
End Class

The user control is not refreshing when I click on the button.... am really having difficult time trying to solve this.. could certainly use some help from you guys....
Thanks
:)

still struggling... need to do this as I suspect it could result in significant performance gains.. anyone on wats wrong with my code?..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.