ASP.NET 1.1: Page vs. Control events

O

Ole Hanson

Hi

I am having a number of User Controls (ascx) on my page (aspx).
The page is in my scenario only working as a dumb "container "giving life to
the Controls, as these are handling my UI-logic and communicating with each
other (the controls are communicating) by subscribing to each others events.
(e.g. pressing a selection in Control1 will "trigger" the content of
Control2).

It is done in this way:
I wire up Control2 to subscribe to events from Control1. This is done in the
Page_Load event of Control2, by first letting Controls2 obtain access to
it's parent (this.Page.Controls) and then locating Control1's events to
subscribe to. It is a quite brilliant framework letting the UI-controls
communicate via the page.

Question: How to I make sure the controls are loaded by the hosting Page,
before doing the eventwiring (Subscribe)??


/Ole
 
J

John Saunders

Ole Hanson said:
Hi

I am having a number of User Controls (ascx) on my page (aspx).
The page is in my scenario only working as a dumb "container "giving life
to
the Controls, as these are handling my UI-logic and communicating with
each
other (the controls are communicating) by subscribing to each others
events.
(e.g. pressing a selection in Control1 will "trigger" the content of
Control2).

It is done in this way:
I wire up Control2 to subscribe to events from Control1. This is done in
the
Page_Load event of Control2, by first letting Controls2 obtain access to
it's parent (this.Page.Controls) and then locating Control1's events to
subscribe to. It is a quite brilliant framework letting the UI-controls
communicate via the page.

Question: How to I make sure the controls are loaded by the hosting Page,
before doing the eventwiring (Subscribe)??

I'm not certain I know what you're asking. Please correct the following if
wrong:

In the Page_Load event of Control2, you want to make sure that Control1 has
already been loaded by the page. This would be because the controls are
being dynamically loaded?

If the controls were statically loaded, then there is nothing to prevent the
Page_Load of Control2 from connecting to the events of Control1. The
Page_Load event of Control1 need not have been executed yet.

Also, as a general thing, it's not good for controls on a page to directly
know about each other. The basic idea is that all of the controls in a page
are independant of each other. However, if you have a situation where the
only purpose of the two controls is to be on the same page together, then I
suppose it's alright. Personally, in a situation like that, I'd still keep
the two controls separate. I'd place them both into a single containing
control. I'd have the container expose each of the contained controls via a
property. It would then be possible for each of the contained controls to
access the public members of the others, via the properties. This way, the
contained controls would not be dependant on finding each other in the
Controls collection of the page, and wouldn't be dependant on the exact
class of the other, etc.

The container would represent "the set of controls which need to closely
interact with each other". The rest of the controls on the page would still
be independant.

John Saunders
 

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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top