using 'sender' object on event fires

P

Phil

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.
 
T

Teemu Keiski

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.
 
P

Phil

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...
 

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
474,135
Messages
2,570,783
Members
47,341
Latest member
hanifree

Latest Threads

Top