开发者

How to use outputcache in a usercontrol, with control properties

I have a UserControl, which should only change based on 2 URL parameters.

The problem is, it has a public property, which is used in the calling pages, so it throws a NullReferenceExc开发者_JAVA技巧eption on my property.

Any ideas?


I think I've figured this one out, it seems to be quite tricky which is due to my lack of comprehensive understanding of how output cache works I suspect.

You can't cache the UserControl if it has variable properties that dicatate it's content. You need to put a cache control in the Content page that holds the control. Then add the cache to the content page:

<%@ OutputCache Duration="120" VaryByControl="JobList" %>

Where the vary by control is the ID of the control you wish to cache. Then specify a property for that vary by control:

<%@ OutputCache Duration="120" VaryByControl="JobList.LoggedInUserID" %>

This seems to work for me!


Check the VaryBy options, try to take a look to this articles:

http://msdn.microsoft.com/en-us/library/hdxfb6cy%28v=vs.71%29.aspx

https://web.archive.org/web/20211020113508/https://www.4guysfromrolla.com/articles/022802-1.aspx

http://weblogs.asp.net/stefansedich/archive/2008/03/17/output-cache-with-usercontrol-on-masterpage-and-multiple-varybycustom.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜