all groups > asp.net building controls > february 2005 >
You're in the

asp.net building controls

group:

Cache a user control based on a Property in the code behind.



Re: Cache a user control based on a Property in the code behind. Wilco Bauwer
2/23/2005 11:23:40 AM
asp.net building controls: You can use output caching and use varybycontrol to base the cache on
the value of a property of the usercontrol. Also take a look at the
quickstarts, or any other kind of documentation, because they describe
these kind of things very well:
http://samples.gotdotnet.com/quickstart/aspplus/doc/fragmentcaching.aspx.
Cache a user control based on a Property in the code behind. MattC
2/23/2005 11:50:24 AM
I have a user control that is placed on every page to provide a menu system,
logout/login buttons etc.

This contect varies in depending on the value of a property in the code
behind file of the control.

How can I cache dependant on the value of that property.

TIA

MattC

Re: Cache a user control based on a Property in the code behind. MattC
2/24/2005 9:23:13 AM
This only gives examples of caching based on properties in the ASPX page I
would like to know if I can cache based on the value of a Code Behind
Property.
[quoted text, click to view]

Re: Cache a user control based on a Property in the code behind. MattC
2/24/2005 9:33:31 AM
I have managed to cache based on a code behind property now but it seems to
not work how I would expect. I have this in my control.
<%@ OutputCache VaryByControl="UserType" Duration="300"%>

in my code begind is a property:

protected string UserType
{
get
{
if(SecurityHandler.ThisUser != null)
_usertype =
SecurityHandler.ThisUser.UserSecurityProfile.SecurityProfileName;

return _usertype;
}
}

UserType will return either Admin, String.Empty, Finance, User.

However when I visit a page it is cached but if I log out and log in as an
account with a different usertype i get the cached copy for the previous
user type, instead of what I expected was ASP.NET to cache a new version for
the new type. It seems the cache the control by the page not by the value
in the property.

TIA

MattC

[quoted text, click to view]

AddThis Social Bookmark Button