Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Passing messages between child controls

  Asked By: Gin    Date: Oct 14    Category: Asp.net    Views: 967
  

I have a user control that contains two child user controls. The
two child user controls need to communicate. What is the
recommended method for communicating between child controls?

I have them communicating through the parent by referencing each
child within the parent (which is the default nature)...then inside
the child, I create a field that contains an reference of the other
child control. From the parent, I set this field equal to the
instance of the other child.

This seems very confusing. Is there a better method?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Abbad Akhtar     Answered On: Oct 14

Well, the parent is the only common link you have, so I suppose you are doing it
right ?

Though I would try to minimise the actual parent's role in things.

I would uuummmmm, from within a child control, to FindControl() the parent (or
NamingContainer), and then FindControl() the child you want of that parent (or
use control  collection), thus not adding any additional code to the parent.

Thats just the way I'd do it, don't know what's sthe "right" way to do things.

I camw across something once where a control was in a page and the control was
being used by the parent in way I am not used to. I tend to, and try to, write
controls that are as independant as possible - but this one sort of minimised
the controls  independance and the container using it was doing half of what it's
work should have been.
I don't know ... it was MS and was bubbling events and all sorts ... but I just
had a natural oversion to the way it was set  up.
I'd like to know more myself to tell the truth.

 
Answer #2    Answered By: Cais Nguyen     Answered On: Oct 14

I'm having troubles designing an application using the tabstrip and
multipage controls  that are in an .aspx file and getting all my
other user  controls (that I drop into that .aspx file) to talk to
each other (pass info, disable one another, set  visibility, etc.).
I ended up placing a reference  in the parent to each child user
control and then placing a reference to the parent in the
child...then, in each child user control, I reference another child
through the parent. So, if I'm flipping from one tab to another, I
enable and set visibility on controls to true.

Have you guys noticed that when you have a button on one pageview of
a multipage and then you click it to move to the next tab (or
pageview of a multipage) that it won't postback when you have a
validation control  on the next page? I found that to be the case
and had to disable the validation control when it loads, then when I
click my button on my first page to move to the second page, I
enable the validation. It's goofy, but it works.

I posted this yesterday and everyone stopped posting. Did I make a
ripple in the ASP.NET community?

 
Answer #3    Answered By: Jaspreet Kapoor     Answered On: Oct 14

I haven't used the tabstrip yet ... too fond of my little client side tabled
version - why bother with a postback if your not updating currently visible data
? - just download it all into tabled tabs and use dhtml display.

Maybe I will have a go with it one day - and will certainly keep this thread as
reference for when I do.

 
Didn't find what you were looking for? Find more on Passing messages between child controls Or get search suggestion and latest updates.




Tagged: