Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of "object sender" and "EventArgs e" parameters?

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.

like image 999
Qasim Avatar asked Jan 23 '13 11:01

Qasim


People also ask

What is object sender and EventArgs in C#?

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

What is sender As object E as EventArgs in VB net?

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.

What is EventArgs?

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.

What is sender in VB net?

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.


1 Answers

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

like image 101
Vinayak Pahalwan Avatar answered Oct 09 '22 12:10

Vinayak Pahalwan