Wednesday, 13 March 2013

ASP.NET: What is (object sender, EventArgs e)


It is a standard in .NET that event handlers have this signature, usually declared by some delegate types for example EventHandler. sender references the object that raised the particular event, for example with Button's Click it would let you reference the Button control via sender argument.
EventArgs represents the data related to that event, and can be used to pass parameters, state information whatsoever to the event handler for the handling code to decide what to do. In this case it is just EventArgs which represents empty event arguments but for example if you have ImageButton's Click handler, you'll note that it's event arguments provide you access to the X and Y coordinates. In other words, Event args can be represented by more specific classes with event related data, depending on the control

No comments:

Post a Comment