In case of Page_Load
, Init
and other page events, what is the use of these (object sender, EventArgs e)
parameters?
Examples would be more helpful.
The C# Object sender is one of the argument, and it's a parameter for creating the reference of the object which has been raised for the events that are used for to respond the handler to mapping the correct object but in case of static parameters or events, the value will be null with the help of EventArgs class we ...
Sender is the object that raised the event and e contains the data of the event. All events in . NET contain such arguments. EventArgs is the base class of all event arguments and doesn't say much about the event.
EventArgs is also the class you use when an event does not have any data associated with it. When you create an event that is only meant to notify other classes that something happened and does not need to pass any data, include the EventArgs class as the second parameter in the delegate. You can pass the EventArgs.
Event subroutines always receive a "sender" object and a system EventArgs parameter "e". Because the EventArgs parameter is an object, it supports whatever properties and methods are necessary. For example, the old VB6 MouseMove event subroutine used to receive four parameters: Button As Integer. Shift As Integer.
EventArgs e
is a parameter called e that contains the event data, see the EventArgs MSDN page for more information.
Object Sender
is a parameter called Sender that contains a reference to the control/object that raised the event.
Event Arg Class: http://msdn.microsoft.com/en-us/library/system.eventargs.aspx
Example:
protected void btn_Click (object sender, EventArgs e){ Button btn = sender as Button; btn.Text = "clicked!"; }
Edit: When Button is clicked, the btn_Click event handler will be fired. The "object sender" portion will be a reference to the button which was clicked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With