Cross user control communication via parent control

Discussion in 'ASP .Net' started by zeya_bakhtyar@hotmail.com, Jul 18, 2007.

  1. Guest

    Here is the page architecture:
    Page loads multiple user controls (including nested user controls)
    dynamically based on parameters provided into place holders. Note: The
    page only has the logic to load the user controls and subscribe to
    custom event exposed in the user controls.

    Scenario:
    User comes to this page fills the fields generated by multiple user
    controls and then hits "Save" button in one of the forms.

    Question:
    - How can all the information be collected in the control that has the
    save button and saved to a repository?
    - Is there a better practise?
    - How can all the user controls be "wired" together to cross
    communicate?

    An example will be great help.

    - Working with ASP.Net 2.0 using C#

    Thanks in advance.
     
    , Jul 18, 2007
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Here is the page architecture:
    > Page loads multiple user controls (including nested user controls)
    > dynamically based on parameters provided into place holders. Note: The
    > page only has the logic to load the user controls and subscribe to
    > custom event exposed in the user controls.


    Did you not see my reply to you? Here it is again:
    -------------
    "zb" <> wrote in message
    news:...
    > Here is the page architecture:
    > Page loads multiple user controls (including nested user controls)
    > dynamically based on parameters provided into place holders. Note: The
    > page only has the logic to load the user controls and subscribe to
    > custom event exposed in the user controls.
    >
    > Scenario:
    > User comes to this page fills the fields generated by multiple user
    > controls and then hits "Save" button in one of the forms.
    >
    > Question:
    > - How can all the information be collected in the control that has the
    > save button and saved to a repository?
    > - Is there a better practise?
    > - How can all the user controls be "wired" together to cross
    > communicate?


    In the same way that you exposed the events from the user controls, you can
    expose properties. Add properties to the user controls which will return the
    data they have gathered from their input controls. The controlling page can
    read those properties and use them to write to the repository.

    I suggest that you do not do what is done by some code I know (you know who
    you are!). Do not have a Save method on each user control, that accepts a
    DataTable. The user control can fill the DataTable with the information it
    has gathered.

    The problem is that you have now closely tied each individual user control
    to the structure of the data in your repository. It is better to separate
    data from presentation. Instead, either have separate properties, or have a
    property that returns a Data Transfer Object (DTO) from the user control. It
    should return a struct containing all of the data collected by the user
    control. Your calling page can take that data and put it into your
    repository however it likes. The nice thing is that the user controls will
    not need to change if the details of your data access layer change.
    --
    John Saunders [MVP]
     
    John Saunders [MVP], Jul 19, 2007
    #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. Alan
    Replies:
    0
    Views:
    377
  2. zb
    Replies:
    1
    Views:
    358
    John Saunders [MVP]
    Jul 18, 2007
  3. zb
    Replies:
    0
    Views:
    348
  4. zb
    Replies:
    1
    Views:
    652
    davidgrover
    Feb 8, 2011
  5. Replies:
    10
    Views:
    209
    Dr J R Stockton
    Feb 23, 2007
Loading...

Share This Page