views:

120

answers:

3

Hi,

I've an asp.net user control called UC_Test which has got a public property exposed called param1.It is hosted in aspx pages A and B.

On page A, param1 is set to 10 and on page B param1 is set to 20. Depending on the param value, the formatting of user control is controlled.

I want page A and page B to cache separates instances of user controls.

As okw has pointed out, I want to use caching for performance reasons and not for persisting values.Please let me know how do i achieve this.

Can I use Shared=false for this purpose?for example?

<%@ OutputCache Duration="3600" VaryByParam="none" Shared="false"%>

Thanks for reading.

A: 

The most straightforward way is to use a HiddenField that holds the appropriate value. Read it back from the page during a form submission or postback call.

John Fisher
A: 

You could do something like:

public int MyProperty
{
 get
 {
  return (int)ViewState[this.UniqueID + "_MyProperty"];
 }

 set
 {
  ViewState[this.UniqueID + "_MyProperty"] = value;
 }
}

ViewState in this scenario being interchangable with HttpContext.Current.Cache or HttpContext.Current.Session. You just need to make sure to check for nulls or whatever.

Hope it helps.

Aaron
+1  A: 

This sounds like an ideal candidate for the VaryByCustom output cache directive. You can just use the value of your property to determine the difference between the cached versions.

See MSDN for the full details: http://msdn.microsoft.com/en-us/library/ms550239.aspx

pattermeister