Kalyan
06-12-2007, 10:33 AM
Hi
I have user control in my application that is used in many of the pages.. it is constant for all the pages..but only changes when the user selects a particular value in a dropdown and clicks on a button... so basically I could cache the control and refresh it in the cache when the user clicks on the button...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...
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
However 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
:)
I have user control in my application that is used in many of the pages.. it is constant for all the pages..but only changes when the user selects a particular value in a dropdown and clicks on a button... so basically I could cache the control and refresh it in the cache when the user clicks on the button...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...
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
However 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
:)