在缓存ASP.NET用户控件? [英] Caching a user control in ASP.NET?

查看:113
本文介绍了在缓存ASP.NET用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序header.ascx创建用户控制,我考取一个selectedMenu属性这种控制在其控制选择指定的selectedMenu值。假如,我已经通过了值家或搜索,然后将选择(高亮显示)的搜索菜单。

I have created a user control in my application "header.ascx", I am pasing a selectedMenu attribute to this control on which the control selects the selectedMenu value specified. Suppose, I have passed value "home" or "search" then it will select (highlight it) the search menu.

我想缓存此控制,当selectedMenu属性的值的变化则只有缓存将刷新其他应拿起从高速缓存控制??

I want to cache this control, When the value of the selectedMenu attribute changes then only the cache will be refreshed else it should picks up the control from cache??

是否可以缓存在asp.net用户控件?我使用ASP.NET 2.0(C#)

Is it possible to cache a user control in asp.net?? I am using ASP.NET 2.0 (C#)

推荐答案

在ASP.NET用户控件缓存被称为的片段缓存。它通过添加一个OutputCache指令到你的页面的顶部做:
<%@的OutputCache时间=120的VaryByParam =无%>

User control caching in ASP.NET is called fragment caching. It's done by adding an OutputCache directive to the top of your page: <%@ OutputCache Duration="120" VaryByParam="None" %>

您无法通过设置控件的属性,因为如果它在缓存中找到的控制是不实际创建改变缓存。如果您尝试访问在code中的控制背后的缓存,这将是空。

You can't vary the cache by setting the property on the control because the control isn't actually created if it's found in the cache. If you try to access the control in the code behind it's cached, it will be null.

是决定控件是否应被缓存的条件或者不是东西,你可以通过查看当前的请求决定?如果是,你可以使用VaryByCustom是属性(<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.partialcachingattribute.varybycustom.aspx\">http://msdn.microsoft.com/en-us/library/system.web.ui.partialcachingattribute.varybycustom.aspx)输出缓存指令,你可以把你在那里为参数想要的任何字符串,然后当缓存评估的 GetVaryByCustomString()方法将被调用,您可以把逻辑控制是否应被缓存或不存在。

Is the condition that determines whether the control should be cached or not something that you can determine by looking at the current request? If it is, you can use the varybycustom attribute (http://msdn.microsoft.com/en-us/library/system.web.ui.partialcachingattribute.varybycustom.aspx) of the output cache directive. You can put any string you want in there as the parameter and then when the caching is evaluated the GetVaryByCustomString() method from Global.asxa will be called and you can put the logic for whether the control should be cached or not there.

这篇关于在缓存ASP.NET用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆