ASP.NET 1.1: Page vs. Control events

Discussion in 'ASP .Net Building Controls' started by Ole Hanson, Nov 16, 2004.

  1. Ole Hanson

    Ole Hanson Guest

    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
     
    Ole Hanson, Nov 16, 2004
    #1
    1. Advertising

  2. "Ole Hanson" <> wrote in message
    news:...
    > 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
     
    John Saunders, Nov 19, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shiv
    Replies:
    0
    Views:
    476
  2. Dan
    Replies:
    1
    Views:
    5,405
    Christophe Gijbels
    Jan 4, 2004
  3. Dan
    Replies:
    5
    Views:
    354
  4. Dan
    Replies:
    3
    Views:
    816
    Alessandro Zifiglio
    Jan 21, 2004
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    366
    Chris
    Aug 30, 2005
Loading...

Share This Page