2

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 NullReferenceException on my property.

Any ideas?

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
thomasb
  • 5,816
  • 10
  • 57
  • 92

2 Answers2

0

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!

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456