Populating web Controls inmedded in a User Control

P

PeteZ

Hi,

I have a web page that extensively uses user controls.

In my Page_Load method in my code behind for the web page I want to populate
some of these controls in the User Controls

How do I address these controls ? They dont seem to be visible as a
"normal" control would be ie. there is no definition of the control in my
code behind code. Do I need to qualify the control name with the User
Control name first ?

Can someone help.

thanks,

- peteZ
 
J

John Saunders

PeteZ said:
Hi,

I have a web page that extensively uses user controls.

In my Page_Load method in my code behind for the web page I want to
populate some of these controls in the User Controls

How do I address these controls ? They dont seem to be visible as a
"normal" control would be ie. there is no definition of the control in my
code behind code. Do I need to qualify the control name with the User
Control name first ?

Can someone help.

Each user control is a class. It is standard in OO for a class to not expose
the details of its implementation. The controls inside of a user control are
implementation details and as such should not be exposed for the external
world to see. Consider - what if you decided to change the set of controls
inside of the user control - should you have to change all of the pages
which reference that user control?

Instead, you can treat the user controls just like any other class. You can
add properties to them which will allow the pages they're on to provide data
to the user controls. You can add events to them so that they can inform the
pages they're on of the things that happen inside of them.

But once you expose the controls inside of the user controls, they will
always have to remain that way, or else you'll have to change all of the
pages which refer to them.


John Saunders
 
P

PeteZ

John,

You should write a book . . . . a very clear response and I understand now.
People make money from those attributes !

many thanks,

- peteZ
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top