T
Tom Kiefer
Question:
If I have an ASP.NET User Control which defines/exposes a property that the
page can use to specify a mode or data subset for the control to use, is
there a way to tell the @OutputCache directive to vary its cache based on
that property value?
I.e., I have:
<my:control runat="server" id="mcOne" Flag="One" />
<my:control runat="server" id="mcTwo" Flag="Two" />
where Flag is a public property of the code-behind class (whose value
affects the display output), and I want the Flag="One" instance to
output-cache separately from the Flag="Two" instance.
So far, the control seems to output-cache only one version of the control,
and all successive displays of the control use that cached version,
regardless of the Flag attribute value.
Other notes:
The @OutputCache directive's VaryByParam attribute works only with GET and
POST values. (I did try VaryByParam="Flag" anyway, to no effect.)
Setting the @OutputCache directive's Shared attribute to "False" solves the
problem (by causing each usage of the control to cache separately), but has
the additional effect of requiring separate initial-loads and caches for
each page on which the control appears. Since I currently only have two or
three possible values of the Flag attribute, but these controls may appear
on many pages (and there is some work invovled in the initial load of the
data for this control), this is not ideal.
There doesn't seem to be any sort of VaryByProperty attribute for
@OutputCache (which surprises me). So...
Any other ideas?
- Tom Kiefer
thogek @ earthlink . net
If I have an ASP.NET User Control which defines/exposes a property that the
page can use to specify a mode or data subset for the control to use, is
there a way to tell the @OutputCache directive to vary its cache based on
that property value?
I.e., I have:
<my:control runat="server" id="mcOne" Flag="One" />
<my:control runat="server" id="mcTwo" Flag="Two" />
where Flag is a public property of the code-behind class (whose value
affects the display output), and I want the Flag="One" instance to
output-cache separately from the Flag="Two" instance.
So far, the control seems to output-cache only one version of the control,
and all successive displays of the control use that cached version,
regardless of the Flag attribute value.
Other notes:
The @OutputCache directive's VaryByParam attribute works only with GET and
POST values. (I did try VaryByParam="Flag" anyway, to no effect.)
Setting the @OutputCache directive's Shared attribute to "False" solves the
problem (by causing each usage of the control to cache separately), but has
the additional effect of requiring separate initial-loads and caches for
each page on which the control appears. Since I currently only have two or
three possible values of the Flag attribute, but these controls may appear
on many pages (and there is some work invovled in the initial load of the
data for this control), this is not ideal.
There doesn't seem to be any sort of VaryByProperty attribute for
@OutputCache (which surprises me). So...
Any other ideas?
- Tom Kiefer
thogek @ earthlink . net