NOTE: I am going to hit the entire topic, so you can see both ways. What you
are asking is the second way.
You can do this declaratively, which is, by far the easiest:
<%@ OutputCache Duration="60" VaryByParam="None" %>
The VaryByParam is most easily implemented by adding properties to the
CodeBehind of your user control. To set parameters in CodeBehind of your
ASPX page, you will have to reference the control. For example, you drag a
control called TopMenu on your ASPX page creating topMenu1
protected TopMenu topMenu1;
You can then set properties in CodeBehind. For example, you have a UserName
property:
topMenu1.UserName = User.Identity.Name;
To set cache programatically use the HttpResponse.Cache Property. This is
from the help file:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(false);
Response.Cache.VaryByParams["Category"] = true;
if (Response.Cache.VaryByParams["Category"])
{
//...
}
A couple of links
http://authors.aspalliance.com/aspxtreme/sys/Web/HttpResponseClassCache.aspx
- overview
http://support.microsoft.com/default.aspx?scid=kb;en-us;323290 - more detail
instructions
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
************************************************
Think Outside the Box!
************************************************
A.M said:
Hi,
How can I change the duration of user control's cache inside asp.net's C#
code?
Any help would be apprecited,
Alan