hey i like what you're saying, but i disagree with you in a lot of
asp.net scenarios, and the reason is that bubbling events is a really
key lever that asp.net provides for you for navigating the event model
gracefully, and if you're not taking advantage of it, odds are, your
asp.net code ends up doing a lot to compensate for control order
execution, which is critical domain because in the web, you can be
frequently rendering the same page in different orders depending on
many scenarios.
bubbling events offers distinct ways in the context of asp.net that are
advantageous beyond that of custom events, in which you have some
immediate and direct control over the execution flow of your various
webcontrols that are also performing their duties.. the situation that
occurs in a poorly written asp.net application is that by bringing a
control into a page, you break the existing page because of event
wiring issues. the costs of continually rewiring events to subscribers
leads me to believe this isn't getting us anywhere closer to the goal
of reducing headache.
anyway, im rambling, but i do think this is a principle that you should
at least spend some time thinking about, if you were interested in
hearing more about why i think you've overlooked something important
about asp.net, this is from msdn: "Event bubbling ensures that the
event handlers for all elements in which an event occurs have an
opportunity to respond to the event"
On Dec 1, 5:07 pm, "Brennan Stehling" <offwh...@gmail.com> wrote:
> Here is what I would do to add event handling support.
>
> I tried the OnBubbleEvent once but it was just counter-intuitive for
> object oriented coding. I prefer defining an event with a good name
> which makes sense the the subscriber. I also like how it gives you
> Intellisense support. Now I simply add events to my child controls and
> subscribe to them.
>
> public event CancelEventHandler ChangingThing;
> public event EventHandler ChangedThing;
>
> There is a lot of ways you can define events now, but I like the above
> syntax the best. The first one is called before change and the second
> one after. The first one uses the CancelEventHandler. Then the
> convention is to create a method like the one below to trigger the
> event.
>
> protected virtual void ChangingThing(CancelEventArgs e)
> {
> if (SendingMail != null)
> {
> SendingMail(this, e);
> }
> }
>
> Where it is called, you will do this.
>
> CancelEventArgs args = new CancelEventArgs();
> OnChangingThing(args);
> if (!args.Cancel)
> {
> // do stuff
> OnChangedThing(EventArgs.Empty);
> }
>
> This way you can have the event prevent an action from taking place. I
> did this for a contact form control. The full source is here...
>
> http://svn.offwhite.net/svn/SmallSha...runk/ClassLibr...
>
> BrennanStehlinghttp://brennan.offwhite.net/blog/
>
>
>
> kferron wrote:
> > The best practices way is to override the OnBubbleEvent on the hosting
> > page.
>
> > In your UserControl, you have it contain its events. When an event
> > occurs, lets say in your ItemCommand eventhandler on the usercontrol,
> > you call RaiseBubbleEvent(source,e).
>
> > This will pass the event properly up the chain without your hosting
> > page needing to know anything about the specific user control.
>
> > Kevin Ferron
>
> > Benton wrote:
> > > > It sounds like you want the Page to tell the User Control to do
> > > > something, or to at least set a value it can use.
>
> > > Actually it's the opposite: I want the UserControl to tell its container
> > > page to do something when "something happens" in the UserControl itself,
> > > i.e., the container page should switch the active view when a button is
> > > clicked on the UserControl.
>
> > > Thanks for any hint,
>
> > > -Benton
>
> > > > What I do is create a public property on User Controls. That exposes a
> > > > value I can set for behavior. Then in the Load or even PreRender event
> > > > handler for the User Control you can use that property to control
> > > > behavior.
>
> > > > What I would not do is set up a method on the User Control because this
> > > > is an event driven model. You will want to stay in that event driven
> > > > model and let the User Control respond to properties as you do with
> > > > controls like TextBox and ListBox. You just adjust properties on those
> > > > controls as well.
>
> > > >BrennanStehling
> > > >http://brennan.offwhite.net/blog/
>
> > > > Benton wrote:
> > > >> Hi there,
>
> > > >> I have a UserControl with a couple of textboxes and a couple of buttons
> > > >> ("Save" and "Cancel"). The Click event for this buttons is in the
> > > >> UserControl's codebehind of course, so here's my question.
>
> > > >> Once the UserControl is dropped onto the container page, how can I
> > > >> perform
> > > >> some action on the codebehind of the container page from the codebehind
> > > >> of
> > > >> the UserControl? For instance, suppose that the UserControl is dropped
> > > >> inside one of the Views of a Multiview control on the container page. By
> > > >> clicking the "Cancel" button of the UserControl, I would like to change
> > > >> the
> > > >> active view of the container page's Multiview control.
>
> > > >> How can this be done in ASP.NET 2.0?
>
> > > >> Thanks in advance,
>
> > > >> -Benton- Hide quoted text -- Show quoted text -