• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1156
  • Last Modified:

(ByVal sender As Object, ByVal e As EventArgs) explanation

Could someone explain the below line of code in real simple terms for me (very new to VB)....

(ByVal sender As Object, ByVal e As EventArgs)

Thanks,
Dean
0
deanlee17
Asked:
deanlee17
2 Solutions
 
DhaestCommented:
ByVal means it is passing the variable by value. http://www.developer.com/net/vb/article.php/3669066

sender is an object of generic type System.Object.     All objects in .NET inheirit from System.Object, as such it is passing the control that is causing the event to fire.

e is an object of type System.EventArgs where EventArgs is the generic Class for event arguments or, the arguments the event is passed.

 

For example, if you turn your button into an ImageButton, by changing <asp:Button ....> into <asp:ImageButton...> but leave everything else the same, the compliation will fail, because ImageButton requires different Event ARguments because it passes those arguments to the event handler.  An imagebutton event handler would be:

Protected Sub ImageButton2_Click(ByVal sender As System.Object, ByVal e As ImageClickEventArgs) Handles ImageButton2_Click

EndSub


Source: http://forums.asp.net/t/1240123.aspx
0
 
Imran Javed ZiaCommented:
Hi,
you generally find this libne with event handler  (ByVal sender As Object, ByVal e As EventArgs)

here sender is object which is creating the event so if ytou have this event for some textbox then you can use it as textbox as and so on

on the other hand e is the event argument and it carries the event information

you can find details on following links:
http://www.codeproject.com/KB/vb/StepByStepEventsInVBNET.aspx
http://visualbasic.about.com/od/learnvbnet/a/eventhandler.htm
Thanks




0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now