passing same property to multiple controls

D

darrel

OK, due to peer pressure, I'm caving into the concept that one should have
the ASPX page TELL the ascx pages what's going on rather than vice versa.
;o)

I have an aspx page that needs to pass a property to the usercontrols it's
loading (some dynamically via codebehind).

I can certainly just pass the property as such:

<control:control1 property="myProperty" />
<control:control2 property="myProperty" />
<control:control3 property="myProperty" />
<control:control4 property="myProperty" />

Not a huge deal, but I was wondering if there was a way to pass the same
property to all controls at once programmitically just to simplify things a
tad. Something like allControlsOnThisPage.myProperty = "whatever"

I imagine I could first search for all controls, set that as an array, then
loop through each one to set all the properties. But, in the end, that seems
like more processing than it's worth.

-Darrel
 
G

Guest

What I did was add a property to the page that copies the value to the user
controls sort of hierarchically. I also had to keep track of the user
controls in array too, but for that one ugly method, it helped keep
everything else neat.
 
D

darrel

What I did was add a property to the page that copies the value to the
user
controls sort of hierarchically. I also had to keep track of the user
controls in array too, but for that one ugly method, it helped keep
everything else neat.

OK, so I could then load the page, scan through the aspx page to grab all of
the controls, then assign the value to them.

In terms of performance, is this overkill?

-Darrel
 
J

John Saunders

darrel said:
OK, so I could then load the page, scan through the aspx page to grab all
of
the controls, then assign the value to them.

In terms of performance, is this overkill?

How many such controls do you have? If you've only got 10 or so, then this
isn't overkill, it's laziness.

John Saunders
 
D

darrel

How many such controls do you have? If you've only got 10 or so, then this
isn't overkill, it's laziness.

Doing the array is laziness? Or declaring the properties one by one manually
in the code is laziness?

My eventual goal is to make this fairly easy for someone else to update
without adding unecessary performance hits.

So, if I leave, and someone needs a new 'site' made, they can just copy the
ASPX page, and then change the parameters for the controls in an easy as
possible way. I thought setting it once would be the way to go, but perhaps
that's just not a practical thing to do in .net?

-Darrel
 
J

John Saunders

darrel said:
Doing the array is laziness? Or declaring the properties one by one
manually
in the code is laziness?

My eventual goal is to make this fairly easy for someone else to update
without adding unecessary performance hits.

So, if I leave, and someone needs a new 'site' made, they can just copy
the
ASPX page, and then change the parameters for the controls in an easy as
possible way. I thought setting it once would be the way to go, but
perhaps
that's just not a practical thing to do in .net?

Darrel,

One idea I gave you in an earlier post was that all of these controls should
derive from the same base class. This would avoid duplication of code. It
would then be possible to recursively search the page for all controls which
derive from this base class. For each of the located controls, you could set
the property, since it would be a property of that base class.

John Saunders
 
D

darrel

One idea I gave you in an earlier post was that all of these controls
should
derive from the same base class. This would avoid duplication of code. It
would then be possible to recursively search the page for all controls which
derive from this base class. For each of the located controls, you could set
the property, since it would be a property of that base class.

Could I not do that without the need to derive from a base class as well?
(Ie, find all controls on the page, recursively go through them to set the
property)?

Deriving controls from a base class is where my lack of understanding OOP
concepts begins to show a bit. ;o)

I'll do some reading on that. Thanks John!

-Darrel
 
J

John Saunders

darrel said:
Could I not do that without the need to derive from a base class as well?
(Ie, find all controls on the page, recursively go through them to set the
property)?

Deriving controls from a base class is where my lack of understanding OOP
concepts begins to show a bit. ;o)

I'll do some reading on that. Thanks John!

How would you set the property, Darrel?

John Saunders
 
D

darrel

How would you set the property, Darrel?

I was thinking you'd get each property ID, and then just start setting them:

projectClass.controlID.property = "whatever"

I don't know. I'm kind of lost on this whole concept of passing variables
between pages and controls. I know I'm not supposed to be thinking in terms
of pages and that's what's throwing me off.

For now, I'm just going to manually set all of these properties and be done
with it, and once this project is underway, hopefully find some time to sit
back and absorb some books on the higher-level .net stuff focussing on the
OOP stuff.

I appreciate all the help/advice you've given!

-Darrel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,785
Messages
2,569,624
Members
45,318
Latest member
LuisWestma

Latest Threads

Top