如何以编程方式删除的OutputCache为ASCX?

编程入门 行业动态 更新时间:2024-10-27 14:21:35
本文介绍了如何以编程方式删除的OutputCache为ASCX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个page1.aspx这个:

I have a page1.aspx:

<%@ Register src="uc1.ascx" tagname="UcHead" tagprefix="uc1" %>

和uc1.ascx使用的OutputCache :

and uc1.ascx using the OutputCache:

<%@ OutputCache Duration="18000" VaryByParam="*" %>

我怎么可以在另一个page2.aspx点击一个按钮来删除的OutputCache 为uc1.ascx或page1.aspx这个?

How can I click a button in another page2.aspx to remove OutputCache for uc1.ascx or page1.aspx?

当的OutputCache在page1.aspx这个,我可以使用下面的code去除的OutputCache:

When the OutputCache is in page1.aspx, I can use the following code to remove the OutputCache:

string url = "/page1.aspx"; HttpResponse.RemoveOutputCacheItem(url);

但是,当的OutputCache是​​uc1.ascx这是行不通的。

But it does not work when the OutputCache is in uc1.ascx.

推荐答案

好吧试试这个

在用户控件放的页面加载速度:

In the page load of your user control put:

HttpRuntime.Cache.Insert("myCacheKey", DateTime.Now); BasePartialCachingControl pcc = Parent as BasePartialCachingControl; pcc.Dependency = new CacheDependency(null, new string[]{"myCacheKey"});

更改关键看你希望它是你控制什么的。

Change the key to whatever you want it to be for your control.

然后在事件code要清除高速缓存的说:

Then in the code of the event that you want to clear the cache put:

Cache.Insert("myCacheKey", DateTime.Now);

我看到在dotnetslackers/ASP_NET/re-63091_ASP_NET_clear_user_control_output_cache.aspx

我测试,它似乎工作,虽然我必须刷新页面再次后,我把这种喜欢看到更新的控制内容。

I tested it and it seems to work, although I do have to refresh the page once again after I call this like to see the updated control content.

更多推荐

如何以编程方式删除的OutputCache为ASCX?

本文发布于:2023-07-27 05:22:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1220586.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   OutputCache   ASCX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!