Qasim Qasim - 1 year ago 88
ASP.NET (C#) Question

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

In case of

and other page events, what is the use of these
(object sender, EventArgs e)

Examples would be more helpful.

Answer Source

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:


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download