|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
using 'sender' object on event firesI understand using the 'sender' object allows you to right a single function
to handle multiple events, but in the instance that you are righting a function for a single event does it buy you anything? For instance (as is my case...), when handling a FormView PreRender event, is it better to reference the FormView control ('FormView1') as this.FormView1, or (FormView)sender, in my function if I'm handling only one event? I've been using the sender object most of the time, but I wonder if I'm just making it more complicated than need be. Thanks. Hi,
it is just standard way to define event handlers in .NET. Sender represents the object which raised the event. That really doesn't then take argument if it's going to be reused or not (the event handler method, I mean) What comes to the single event case, I might even suggest using this.FormView. as that removes the need to do casting at all...since you already have the member and you know it is the only one raising the event. -- Teemu Keiski ASP.NET MVP, AspInsider Finland, EU http://blogs.aspadvice.com/joteke Show quoteHide quote "Phil" <P***@discussions.microsoft.com> wrote in message news:060BA208-3F0C-4691-BDDD-D3B6EBC06535@microsoft.com... >I understand using the 'sender' object allows you to right a single >function > to handle multiple events, but in the instance that you are righting a > function for a single event does it buy you anything? > > For instance (as is my case...), when handling a FormView PreRender event, > is it better to reference the FormView control ('FormView1') as > this.FormView1, or (FormView)sender, in my function if I'm handling only > one > event? > > I've been using the sender object most of the time, but I wonder if I'm > just > making it more complicated than need be. > > Thanks. Thanks for the reply. This is essentially what I believed to be the case -
it is more effecient to use the actual object, rather than 'sender' since there will be no casting or object creation. I also noticed i said 'right' instead of 'write' in my original post. Whoops... Show quoteHide quote "Teemu Keiski" wrote: > Hi, > > it is just standard way to define event handlers in .NET. Sender represents > the object which raised the event. That really doesn't then take argument if > it's going to be reused or not (the event handler method, I mean) > > What comes to the single event case, I might even suggest using > this.FormView. as that removes the need to do casting at all...since you > already have the member and you know it is the only one raising the event. > > -- > Teemu Keiski > ASP.NET MVP, AspInsider > Finland, EU > http://blogs.aspadvice.com/joteke > > "Phil" <P***@discussions.microsoft.com> wrote in message > news:060BA208-3F0C-4691-BDDD-D3B6EBC06535@microsoft.com... > >I understand using the 'sender' object allows you to right a single > >function > > to handle multiple events, but in the instance that you are righting a > > function for a single event does it buy you anything? > > > > For instance (as is my case...), when handling a FormView PreRender event, > > is it better to reference the FormView control ('FormView1') as > > this.FormView1, or (FormView)sender, in my function if I'm handling only > > one > > event? > > > > I've been using the sender object most of the time, but I wonder if I'm > > just > > making it more complicated than need be. > > > > Thanks. > > >
DataMappingType in the DataSet Designer
UserControls and Collections Property I do I remove the style attribute from Image controls? HyperLinkField and FindControl FormView - initial template UserControl Problem in designing layout of website project or website location in design time Gridview Pager Modes Gridview can't format a date |
|||||||||||||||||||||||