Delegating Events between User Controls?

J

Johannes Eble

Hello community,

let's say I have a web form containing two User Controls, usrA and
usrB, respectively.

usrA.ascx has (among others) a Dropdown List ddL1 with
Autopostback=True and a ddL1_SelectedIndexChanged Handler.
usrB itsself has a child user control, usrBB.

I must delegate the ddL1_SelectedIndexChanged Event from usrA to
usrBB. How do I do that?

Is it really necessary to delegate (or bubble) the event from usrA to
the web form, then delgate the event from the web form to usrB, and
finally delegate the event from usrB to usrBB?

It seems that there is no way to 'reverse-bubble' the event from the
web form to usrBB or - better - to 'cross-bubble' the event from usrA
to usrBB.
In other words, there is no way for usrBB to access usrA (for event
registering) without extremly ugly casts.


Any ideas?


Best regards


Johannes
 
R

Raterus

Is it really necessary to delegate (or bubble) the event from usrA to
the web form, then delgate the event from the web form to usrB, and
finally delegate the event from usrB to usrBB?

Yes! You break the Object-orientated approach to it if you do it any other way. (I'm not saying it can't be done, but I wouldn't do it) Create an event your usercontrol fires which you handle at your main page, and then push your way down to usrBB through usrB.

--Michael
 
J

Johannes Eble

Hello Michael,

first, thanks very much for your answer.


Yes! You break the Object-orientated approach to it if you do it any other way. (I'm not saying it can't be done, but I wouldn't do it) Create an event your usercontrol fires which you handle at your main page, and then push your way down to usrBB through usrB.

--Michael

The main problem is that there is no event broadcasting.

Another problem is exactly this 'push your way down to usrBB through
usrB'.

Version1:

usrBB's Event-Handler is public, usrBB is a public member of usrB,
usrB and usrA are members of webForm1.

webForm1 registers usrBB's Event-Handler something like:

this.usrA.UsrA_ListChanged += new
usrA.UsrA_ListChangedHandler(this.usrB.usrBB.UsrA_ListChanged);

Version2:

I have to define a new event in webForm1. usrB has to register for
this event. I have to define another new event in usrB to have usrBB
registered. These new events are only for delegating the webForm1's
event (coming from the ddList in usrA) to usrBB.

Version3:

as described in

http://www.123aspx.com/redir.aspx?res=28491

Here the casts get very ugly although he 'only' has to transfer events
between User Controls directly under the main web form.

I have decided to use Version1, so I break encapsulation. Version2
just seems too cumbersome to me.

Now, suppose I hat to put another usrB1 in between usrB and usrBB.
Then I had to close the chain the hard way...



Best regards


Johannes









Well, in a way I have to break the Object-oriented approach, I have to
break encapsulation.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top