473,769 Members | 4,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bubbling Events

Hello,

I am aware that in ASP.NET there is the concept of event bubbling. What I am
after is some advice on achieveing the same thing in a standard application.

Say I have 3 classes. View, Controller and Model.

View calls Controller and then Controller calls Model.

I would like Model to raise events which the View can handle.

What is the best practice way to achieve this? Should i just raise the event
in Model and then re-raise it in the Controller? Or is there a better way?

Thanks
Paul
Sep 22 '08 #1
5 1545
On Mon, 22 Sep 2008 12:08:04 -0700, Paul <Pa**@discussio ns.microsoft.co m>
wrote:
I am aware that in ASP.NET there is the concept of event bubbling. What
I am
after is some advice on achieveing the same thing in a standard
application.

Say I have 3 classes. View, Controller and Model.

View calls Controller and then Controller calls Model.

I would like Model to raise events which the View can handle.

What is the best practice way to achieve this? Should i just raise the
event
in Model and then re-raise it in the Controller? Or is there a better
way?
I suppose that depends on your interpretation of the MVC design pattern.

You certainly can use the controller as a proxy as you suggest, forwarding
events from the model to the view. In that design, the view would be
aware of the controller and would subscribe itself to the events in the
controller.

An alternative would be to have the view implement some interface that
includes event handlers, and have the controller simply subscribe those
event handlers to the model's events.

Of course, I'm speaking generalities here. I understand that there's an
actual MVC framework in ASP.NET, and it's possible that there's some sort
of pre-defined convention in that framework you could follow.

I don't know anything about that particular part of .NET though, and this
isn't the best forum for ASP.NET questions (my understanding is that there
is in fact an ASP.NET-specific newsgroup). If you want an answer that is
truly ASP.NET-specific describing how the ASP.NET behavior would be
implemented outside of ASP.NET, you should probably post your question in
the ASP.NET-specific newsgroup.

Pete
Sep 22 '08 #2
sorry maybe using MVC was a bad example. Lets just say it 3 classes in a
hierarchy. The class at the bottom is the event raiser. The class at the top
must handle the events...but it can only talk to the middle class. And the
middle class can only talk to the bottom class. It's not asp.net.

"Peter Duniho" wrote:
On Mon, 22 Sep 2008 12:08:04 -0700, Paul <Pa**@discussio ns.microsoft.co m>
wrote:
I am aware that in ASP.NET there is the concept of event bubbling. What
I am
after is some advice on achieveing the same thing in a standard
application.

Say I have 3 classes. View, Controller and Model.

View calls Controller and then Controller calls Model.

I would like Model to raise events which the View can handle.

What is the best practice way to achieve this? Should i just raise the
event
in Model and then re-raise it in the Controller? Or is there a better
way?

I suppose that depends on your interpretation of the MVC design pattern.

You certainly can use the controller as a proxy as you suggest, forwarding
events from the model to the view. In that design, the view would be
aware of the controller and would subscribe itself to the events in the
controller.

An alternative would be to have the view implement some interface that
includes event handlers, and have the controller simply subscribe those
event handlers to the model's events.

Of course, I'm speaking generalities here. I understand that there's an
actual MVC framework in ASP.NET, and it's possible that there's some sort
of pre-defined convention in that framework you could follow.

I don't know anything about that particular part of .NET though, and this
isn't the best forum for ASP.NET questions (my understanding is that there
is in fact an ASP.NET-specific newsgroup). If you want an answer that is
truly ASP.NET-specific describing how the ASP.NET behavior would be
implemented outside of ASP.NET, you should probably post your question in
the ASP.NET-specific newsgroup.

Pete
Sep 22 '08 #3
On Mon, 22 Sep 2008 13:00:14 -0700, Paul <Pa**@discussio ns.microsoft.co m>
wrote:
sorry maybe using MVC was a bad example. Lets just say it 3 classes in a
hierarchy. The class at the bottom is the event raiser. The class at the
top
must handle the events...but it can only talk to the middle class. And
the
middle class can only talk to the bottom class. It's not asp.net.
I don't see how the re-framed question changes my response. My response
was generic in the first place, necessarily ignoring the ASP.NET details
(because I don't know anything about them).

I only mentioned the ASP.NET-specific stuff in case you were looking for
something that specifically follows an ASP.NET model. If you don't care
about that, then hopefully my previous reply is useful as-is.

Pete
Sep 22 '08 #4
hi

sorry. what im asking is what is the best practice way (if there is one) of
getting the events from the bottom to the top.

As i see it i could...

(1) have events raised at the bottom and handled in the middle and then
re-raised in the middle and handled again at the top. this seems like
duplication of effort and like re-throwing exceptions im not sure if it is
frowned upon or not.

(2) i could pass the event around from the middle to the bottom. again im
not sure if i like the idea of passing events around. im not sure if this has
impacts from a thread safety / overhead standpoint.

"Peter Duniho" wrote:
On Mon, 22 Sep 2008 13:00:14 -0700, Paul <Pa**@discussio ns.microsoft.co m>
wrote:
sorry maybe using MVC was a bad example. Lets just say it 3 classes in a
hierarchy. The class at the bottom is the event raiser. The class at the
top
must handle the events...but it can only talk to the middle class. And
the
middle class can only talk to the bottom class. It's not asp.net.

I don't see how the re-framed question changes my response. My response
was generic in the first place, necessarily ignoring the ASP.NET details
(because I don't know anything about them).

I only mentioned the ASP.NET-specific stuff in case you were looking for
something that specifically follows an ASP.NET model. If you don't care
about that, then hopefully my previous reply is useful as-is.

Pete
Sep 22 '08 #5
On Mon, 22 Sep 2008 13:30:01 -0700, Paul <Pa**@discussio ns.microsoft.co m>
wrote:
sorry. what im asking is what is the best practice way (if there is one)
of
getting the events from the bottom to the top.
Out of context, it's my opinion that describing a "best practice" isn't
possible. There are surely situations where proxying makes a lot of
sense. That said...
(1) have events raised at the bottom and handled in the middle and then
re-raised in the middle and handled again at the top. this seems like
duplication of effort and like re-throwing exceptions im not sure if it
is
frowned upon or not.
I think if you can avoid this, you should. You won't always be able to,
but you're right that it involves extra overhead.
(2) i could pass the event around from the middle to the bottom. again im
not sure if i like the idea of passing events around. im not sure if
this has
impacts from a thread safety / overhead standpoint.
You can't pass an event. It's not something that is instantiated,
referenced, etc. So obviously this approach is not valid.

A third approach, one I mentioned before, is valid: having the middle
class subscribe a method of the top class to an event of the bottom
class. This would rely on either the top class exposing the handler
publicly, or having the top class provide a delegate instance (perhaps via
a property or method that returns the delegate) that can be attached to
the bottom class's event.

It's not a perfect metaphor, but I think of this third approach as being
more of a "push" approach, and the first approach as being more of a
"pull" approach. That is, in the third approach, the middle class is
pushing events onto the top class. In the first approach, the top class
is pulling events from the middle class.

So, if you have a preference between "push" and "pull", that could help
guide your design decision as well.

You could in fact implement an intermediate design in which the top class
explicitly passed a delegate instance to the middle class, rather than
waiting for the middle class to ask it for one, and then relied on the
middle class to subscribe that delegate instance to the bottom class's
event. In that respect, the top class is doing a bit of pulling by
driving the subscription process, while still allowing the middle class to
do a bit of pushing (by taking care of the subscription to the actual
event).

Pete
Sep 22 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1403
by: john | last post by:
I1. notice that if you have an onclick event for both the document and for a particular element, the onclick for the element is called first and then it bubbles up to the one for the document. Is it possible to have an onclick event that is at the document level that is called first? I would like to intercept it there and return false so that it doesn't bubble down to the element level. 2. On a completely unrelated topic, is it possible...
4
10122
by: Andy | last post by:
Alright, I am beyond confused here and need some guidance. I need a C# only sample. I have a simple Page and within it i am creating a user control (ascx). The user control contains textboxes, buttons, ect. I would like to catch/add a handler/recieve the Button.OnClick event from the buttons that are in the user control, in the Page. How? As far as I can tell, my only route is to: RaiseBubbleEvent in the Button.OnClick in the...
4
1957
by: Wee Bubba | last post by:
the following event handler checks to see if any parent control has attached to the event 'SearchItemSelect'. i use it for event bubbling whenever one of my search items has been selected and at the moment i am calling this from a repeater's ItemCommand event handler: protected void OnSearchItemSelect(EventArgs e) { if (SearchItemSelect != null) { SearchItemSelect (this, e);
7
2145
by: comzy | last post by:
I have created an event bubbling for my pager control which is used for implementing paging in data grid. Althoug it worked very fine in .NET 1.1 it is throwing the following error after i migrated it to .NET 2.0 The peculiar thing abou that is it is throwing error only in IE 6.0 and it works fine in netscape, firefox, opera even after converting it to ..NET 2.0 Can anyone tell me whether anything has changed in event bubbling format...
9
1577
by: pamelafluente | last post by:
Hi guys, After the Exception question, I have another one, strictly related. I would also like what is your preferred device to bubble a message (not by exception) to the user Interface. Assume for instance the following simple schema. What is the best way to bubble the "Status" string message to the UI ? Please suggest appropriate code changes.
5
1178
by: vbgunz | last post by:
I tested the following script in Konqueror 3, Safari 3, Firefox 2 and Opera 9. All browsers work as expected and all browsers are exactly the same in there results. I have 3 peculiar problems I hope I commented well on the following pastebin. http://dpaste.com/hold/26276/ I did not include the HTML but did include the snippet in which this script deals with (at the tail end of the paste). I am still very new in learning JavaScript so...
5
4850
by: Zaxxon21 | last post by:
I'm basically trying to implement a simple drop down menu list for a button that I have. When the user hovers over the button, I want a list of button options to appear below the button. If the users mouse leaves the button, or the buttons in the list I want the list to disappear. I originally tried to place all of the drop down buttons into a single user control, and to then have them appear when users enter some button and disappear when...
2
1671
by: alhalayqa | last post by:
hi, in MSIE, you can attach onclick event to both anchor and document objects. here is some code : document.onclick = function() {alert('document clicked ...'); } <a href= " " onclick="clickHandler"></a>
1
1311
by: m.bagattini | last post by:
Hello folks, I'm in trouble with an application using methodologies in subject. The idea is to have a single-page application. The host aspx page coordinates all visualizations, loading and populating different usercontrols on a status basis. To listen for changes I'm bubbling up events from the usercontrols. Each event raises up to the host aspx page, which decides what to do, what to load etc.
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9849
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.