I did not find .NET Events - What are object sender & EventArgs e? post much helpful.
It primarily tells that how the parameters (object sender, EventArgs e) are used in case of onClick scenario, which turns out to be the obvious use.
My question is :
Neglecting the onClick function
ie 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 :-)
Well it's pretty simple:
object sender
is the entity which emitted the event - in case of page_load i'm pretty sure it is the page itself, because the page is emitting the event (so this == sender
should be true in the page). EventArgs e
is boring (it's a base class), but other events bring more interesting classes which tell something about the event, so a onMouseDown-Event for example will bring data about the mouse position on screen. Other events might bring other data - but most times the Event itself and the sender are enough to get all data needed.
Using standard(similar) signature such as (sender, eventargs)
is beneficial because
Now, once you accept/agree some standards, you need to stick them (even though in certain cases, it may not make sense provided that there is no huge cost associated with). .NET Fx developers has decided on this standard event template and that what's you will see everywhere.
Let's take an example of Page_Load
- this event is actually declared at Control level . So its possible that some code may choose to handle multiple control's load event using the same event handler and use sender
argument to apply specific things.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.