Saturday, March 31, 2012

sharing data between custom controls

I have two custom controls on a page that work on the same object that needs
some prepping when first loaded. Currently I just load them in both controls
individually, essentially doing the same work twice.
What's the best way to share data between controls? I know I could place the
data in HttpContext, but would I essentially be tripling the amount of
memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
control2. Unless context works by reference. Otherwise, is there a better
way? The controls inherit from a common class already -- is there any way to
have a variable in that parent class that is shared within a page?
ThanksBTW -- there's no need to persist the data after the page is rendered. Sorry
I didn't clarify this. It's just data used while rendering the controls. The
data is needed by various controls.
"axis" <justposttothenewsgroup@.nospam.com> wrote in message
news:qoy4d.97680$D%.48936@.attbi_s51...
>I have two custom controls on a page that work on the same object that
>needs some prepping when first loaded. Currently I just load them in both
>controls individually, essentially doing the same work twice.
> What's the best way to share data between controls? I know I could place
> the data in HttpContext, but would I essentially be tripling the amount of
> memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
> control2. Unless context works by reference. Otherwise, is there a better
> way? The controls inherit from a common class already -- is there any way
> to have a variable in that parent class that is shared within a page?
> Thanks
>
Create the object at the page level and pass it to both controls.
Jonathan Allen
"axis" <justposttothenewsgroup@.nospam.com> wrote in message
news:qoy4d.97680$D%.48936@.attbi_s51...
> I have two custom controls on a page that work on the same object that
needs
> some prepping when first loaded. Currently I just load them in both
controls
> individually, essentially doing the same work twice.
> What's the best way to share data between controls? I know I could place
the
> data in HttpContext, but would I essentially be tripling the amount of
> memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
> control2. Unless context works by reference. Otherwise, is there a better
> way? The controls inherit from a common class already -- is there any way
to
> have a variable in that parent class that is shared within a page?
> Thanks
>

0 comments:

Post a Comment