What do sender and eventArgs mean/refer to? How can I make use of them (for the scenario below)?
Scenario:
I'm trying to build a custom control with a delete function, and I want to be able to delete the control that was clicked on a page that contains many of the same custom control.
FYI,
sender
ande
are not specific to ASP.NET or to C#. See Events (C# Programming Guide) and Events in Visual Basic.sender
refers to the object that invoked the event that fired the event handler. This is useful if you have many objects using the same event handler.EventArgs
is something of a dummy base class. In and of itself it's more or less useless, but if you derive from it, you can add whatever data you need to pass to your event handlers.When you implement your own events, use an
EventHandler
orEventHandler<T>
as their type. This guarantees that you'll have exactly these two parameters for all your events (which is a good thing).The sender is the control that the action is for (say OnClick, it's the button).
The EventArgs are arguments that the implementor of this event may find useful. With OnClick it contains nothing good, but in some events, like say in a GridView 'SelectedIndexChanged', it will contain the new index, or some other useful data.
What Chris is saying is you can do this:
Manually cast the sender to the type of your custom control, and then use it to delete or disable etc. Eg, something like this:
The 'sender' is just the object that was actioned (eg clicked).
The event args is subclassed for more complex controls, eg a treeview, so that you can know more details about the event, eg exactly where they clicked.
'sender' is called object which has some action perform on some control
'event' its having some information about control which has some behavoiur and identity perform by some user.when action will generate by occuring for event add it keep within array is called event agrs