[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

RE: Caching a parameterized UserControl

Manish Bafna

12/28/2006 9:27:00 AM

Hi,
As it is usercontrol you need to use fragment caching.You will find
following link on fragment caching useful:
http://support.microsoft.com...

Thanks and Regards,
Manish Bafna.
MCP and MCTS.

"Erik Cassel" wrote:

> I have a UserControl with a public property that defines what it renders. The
> containing Page sets this property. How can I cache my control?
>
> There is no QueryString value associated with the controlâ??s value
> (VaryByParam), the controlâ??s content canâ??t be associated with a global
> property (VaryByCustom) and there is not control contained within this
> UserControl to vary by (VaryByControl).
>
> Any ideas?
>
5 Answers

Erik Cassel

12/29/2006 6:49:00 AM

0


Well, yes. This is fragment caching.

My point is that the control's rendered output isn't dependent on a url
querystring paramenter, isn't dependent on a child Control value, and it
isn't dependent on a global "custom" property. The rendering of the Control
is dependent on a public property I defined for the Control (like an ID into
a table). I see no way of varying the Control's cache under these
circumstances.

Maybe it just isn't possible/applicable and I should stick to data caching...

-Erik


"Manish Bafna" wrote:

> Hi,
> As it is usercontrol you need to use fragment caching.You will find
> following link on fragment caching useful:
> http://support.microsoft.com...
>
> Thanks and Regards,
> Manish Bafna.
> MCP and MCTS.
>
> "Erik Cassel" wrote:
>
> > I have a UserControl with a public property that defines what it renders. The
> > containing Page sets this property. How can I cache my control?
> >
> > There is no QueryString value associated with the controlâ??s value
> > (VaryByParam), the controlâ??s content canâ??t be associated with a global
> > property (VaryByCustom) and there is not control contained within this
> > UserControl to vary by (VaryByControl).
> >
> > Any ideas?
> >

vc

12/31/2006 1:08:00 PM

0

Hello Erik,

What is driving the value of your control's public property?

For varyby caching to work the thing that it's varying by has to be
*somewhere* in the request context.

Martin

"Erik Cassel" <ErikCassel@discussions.microsoft.com> wrote in message
news:4D032533-5FB8-4739-97A3-FE17B1AECA3A@microsoft.com...
>
> Well, yes. This is fragment caching.
>
> My point is that the control's rendered output isn't dependent on a url
> querystring paramenter, isn't dependent on a child Control value, and it
> isn't dependent on a global "custom" property. The rendering of the
> Control
> is dependent on a public property I defined for the Control (like an ID
> into
> a table). I see no way of varying the Control's cache under these
> circumstances.
>
> Maybe it just isn't possible/applicable and I should stick to data
> caching...
>
> -Erik
>
>
> "Manish Bafna" wrote:
>
>> Hi,
>> As it is usercontrol you need to use fragment caching.You will find
>> following link on fragment caching useful:
>> http://support.microsoft.com...
>>
>> Thanks and Regards,
>> Manish Bafna.
>> MCP and MCTS.
>>
>> "Erik Cassel" wrote:
>>
>> > I have a UserControl with a public property that defines what it
>> > renders. The
>> > containing Page sets this property. How can I cache my control?
>> >
>> > There is no QueryString value associated with the control's value
>> > (VaryByParam), the control's content can't be associated with a global
>> > property (VaryByCustom) and there is not control contained within this
>> > UserControl to vary by (VaryByControl).
>> >
>> > Any ideas?
>> >


Erik Cassel

1/3/2007 7:03:00 PM

0

Thanks for your reply. Good question!

Yes, the data that is being varied by does exist â?? perhaps as a querystring
param, perhaps by the logged-on identity, perhaps by postback data. But the
*control* doesnâ??t necessarily know what the param is.

When I design a reusable control, then the controlâ??s container usually tells
the control what to display (by setting a property, for example). On one page
the arg might be â??userIdâ? on the next page the arg might be â??idâ?, but the
control doesn't know that; the container does. This information is
Page-specific and not control-specific, but the OutputCache directive needs
to be put in the Controlâ??s ascx.

Perhaps the answer is to programmatically set the caching info. The
Controlâ??s container could tell the control what to vary by. That way
knowledge of data and knowledge of "varyby" reside at the same place. It
makes the coding a little more complicated, but it might workâ?¦

-Erik





"Martin" wrote:

> Hello Erik,
>
> What is driving the value of your control's public property?
>
> For varyby caching to work the thing that it's varying by has to be
> *somewhere* in the request context.
>
> Martin
>
> "Erik Cassel" <ErikCassel@discussions.microsoft.com> wrote in message
> news:4D032533-5FB8-4739-97A3-FE17B1AECA3A@microsoft.com...
> >
> > Well, yes. This is fragment caching.
> >
> > My point is that the control's rendered output isn't dependent on a url
> > querystring paramenter, isn't dependent on a child Control value, and it
> > isn't dependent on a global "custom" property. The rendering of the
> > Control
> > is dependent on a public property I defined for the Control (like an ID
> > into
> > a table). I see no way of varying the Control's cache under these
> > circumstances.
> >
> > Maybe it just isn't possible/applicable and I should stick to data
> > caching...
> >
> > -Erik
> >
> >
> > "Manish Bafna" wrote:
> >
> >> Hi,
> >> As it is usercontrol you need to use fragment caching.You will find
> >> following link on fragment caching useful:
> >> http://support.microsoft.com...
> >>
> >> Thanks and Regards,
> >> Manish Bafna.
> >> MCP and MCTS.
> >>
> >> "Erik Cassel" wrote:
> >>
> >> > I have a UserControl with a public property that defines what it
> >> > renders. The
> >> > containing Page sets this property. How can I cache my control?
> >> >
> >> > There is no QueryString value associated with the control's value
> >> > (VaryByParam), the control's content can't be associated with a global
> >> > property (VaryByCustom) and there is not control contained within this
> >> > UserControl to vary by (VaryByControl).
> >> >
> >> > Any ideas?
> >> >
>
>
>

vc

1/3/2007 9:36:00 PM

0

I think VaryByCustom is what you need.

You would say something like VaryByCustom="myparam" in the outputcache
directive.

Then in the global.asax HttpApplication.GetVaryByCustomString (specific to
each web app you use your control in) you return the appropriate value for
"myparam".

NB If you really expect to use the control in multiple web apps, you may be
better off considering a custom server control instead.
Then you have much more flexibility and power. (eg use the
System.Web.Caching.Cache object explicitly in code)

Martin

"Erik Cassel" <ErikCassel@discussions.microsoft.com> wrote in message
news:762AFD91-9C18-43DE-8285-24E79DD83EEC@microsoft.com...
> Thanks for your reply. Good question!
>
> Yes, the data that is being varied by does exist - perhaps as a
> querystring
> param, perhaps by the logged-on identity, perhaps by postback data. But
> the
> *control* doesn't necessarily know what the param is.
>
> When I design a reusable control, then the control's container usually
> tells
> the control what to display (by setting a property, for example). On one
> page
> the arg might be "userId" on the next page the arg might be "id", but the
> control doesn't know that; the container does. This information is
> Page-specific and not control-specific, but the OutputCache directive
> needs
> to be put in the Control's ascx.
>
> Perhaps the answer is to programmatically set the caching info. The
> Control's container could tell the control what to vary by. That way
> knowledge of data and knowledge of "varyby" reside at the same place. It
> makes the coding a little more complicated, but it might work.
>
> -Erik
>
>
>
>
>
> "Martin" wrote:
>
>> Hello Erik,
>>
>> What is driving the value of your control's public property?
>>
>> For varyby caching to work the thing that it's varying by has to be
>> *somewhere* in the request context.
>>
>> Martin
>>
>> "Erik Cassel" <ErikCassel@discussions.microsoft.com> wrote in message
>> news:4D032533-5FB8-4739-97A3-FE17B1AECA3A@microsoft.com...
>> >
>> > Well, yes. This is fragment caching.
>> >
>> > My point is that the control's rendered output isn't dependent on a url
>> > querystring paramenter, isn't dependent on a child Control value, and
>> > it
>> > isn't dependent on a global "custom" property. The rendering of the
>> > Control
>> > is dependent on a public property I defined for the Control (like an ID
>> > into
>> > a table). I see no way of varying the Control's cache under these
>> > circumstances.
>> >
>> > Maybe it just isn't possible/applicable and I should stick to data
>> > caching...
>> >
>> > -Erik
>> >
>> >
>> > "Manish Bafna" wrote:
>> >
>> >> Hi,
>> >> As it is usercontrol you need to use fragment caching.You will find
>> >> following link on fragment caching useful:
>> >> http://support.microsoft.com...
>> >>
>> >> Thanks and Regards,
>> >> Manish Bafna.
>> >> MCP and MCTS.
>> >>
>> >> "Erik Cassel" wrote:
>> >>
>> >> > I have a UserControl with a public property that defines what it
>> >> > renders. The
>> >> > containing Page sets this property. How can I cache my control?
>> >> >
>> >> > There is no QueryString value associated with the control's value
>> >> > (VaryByParam), the control's content can't be associated with a
>> >> > global
>> >> > property (VaryByCustom) and there is not control contained within
>> >> > this
>> >> > UserControl to vary by (VaryByControl).
>> >> >
>> >> > Any ideas?
>> >> >
>>
>>
>>


Erik Cassel

1/7/2007 8:26:00 AM

0


Thanks for the ideas Martin, and thanks for hanging in there with my
evolving questions,

-Erik


"Martin" wrote:

> I think VaryByCustom is what you need.
>
> You would say something like VaryByCustom="myparam" in the outputcache
> directive.
>
> Then in the global.asax HttpApplication.GetVaryByCustomString (specific to
> each web app you use your control in) you return the appropriate value for
> "myparam".
>
> NB If you really expect to use the control in multiple web apps, you may be
> better off considering a custom server control instead.
> Then you have much more flexibility and power. (eg use the
> System.Web.Caching.Cache object explicitly in code)
>
> Martin
>
> "Erik Cassel" <ErikCassel@discussions.microsoft.com> wrote in message
> news:762AFD91-9C18-43DE-8285-24E79DD83EEC@microsoft.com...
> > Thanks for your reply. Good question!
> >
> > Yes, the data that is being varied by does exist - perhaps as a
> > querystring
> > param, perhaps by the logged-on identity, perhaps by postback data. But
> > the
> > *control* doesn't necessarily know what the param is.
> >
> > When I design a reusable control, then the control's container usually
> > tells
> > the control what to display (by setting a property, for example). On one
> > page
> > the arg might be "userId" on the next page the arg might be "id", but the
> > control doesn't know that; the container does. This information is
> > Page-specific and not control-specific, but the OutputCache directive
> > needs
> > to be put in the Control's ascx.
> >
> > Perhaps the answer is to programmatically set the caching info. The
> > Control's container could tell the control what to vary by. That way
> > knowledge of data and knowledge of "varyby" reside at the same place. It
> > makes the coding a little more complicated, but it might work.
> >
> > -Erik
> >
> >
> >
> >
> >
> > "Martin" wrote:
> >
> >> Hello Erik,
> >>
> >> What is driving the value of your control's public property?
> >>
> >> For varyby caching to work the thing that it's varying by has to be
> >> *somewhere* in the request context.
> >>
> >> Martin
> >>
> >> "Erik Cassel" <ErikCassel@discussions.microsoft.com> wrote in message
> >> news:4D032533-5FB8-4739-97A3-FE17B1AECA3A@microsoft.com...
> >> >
> >> > Well, yes. This is fragment caching.
> >> >
> >> > My point is that the control's rendered output isn't dependent on a url
> >> > querystring paramenter, isn't dependent on a child Control value, and
> >> > it
> >> > isn't dependent on a global "custom" property. The rendering of the
> >> > Control
> >> > is dependent on a public property I defined for the Control (like an ID
> >> > into
> >> > a table). I see no way of varying the Control's cache under these
> >> > circumstances.
> >> >
> >> > Maybe it just isn't possible/applicable and I should stick to data
> >> > caching...
> >> >
> >> > -Erik
> >> >
> >> >
> >> > "Manish Bafna" wrote:
> >> >
> >> >> Hi,
> >> >> As it is usercontrol you need to use fragment caching.You will find
> >> >> following link on fragment caching useful:
> >> >> http://support.microsoft.com...
> >> >>
> >> >> Thanks and Regards,
> >> >> Manish Bafna.
> >> >> MCP and MCTS.
> >> >>
> >> >> "Erik Cassel" wrote:
> >> >>
> >> >> > I have a UserControl with a public property that defines what it
> >> >> > renders. The
> >> >> > containing Page sets this property. How can I cache my control?
> >> >> >
> >> >> > There is no QueryString value associated with the control's value
> >> >> > (VaryByParam), the control's content can't be associated with a
> >> >> > global
> >> >> > property (VaryByCustom) and there is not control contained within
> >> >> > this
> >> >> > UserControl to vary by (VaryByControl).
> >> >> >
> >> >> > Any ideas?
> >> >> >
> >>
> >>
> >>
>
>
>