Last post Mar 28, 2008 09:57 PM by ritvikd
Mar 28, 2008 09:37 PM|maxmax|LINK
I am developing asp.net web application and in my webform I have button
in my code behid file I have following
some one tell me what is ByVal sender
and what is does
Mar 28, 2008 09:53 PM|jpuckett|LINK
ByVal means it is passing the variable by value.
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
Inside the sub, type e. and see what Intellisense pops up for you vs the Button_Click e.
Mar 28, 2008 09:54 PM|Mansoor Ali Sadiq|LINK
It is the object that raised this handler........In your case its Button2
Mar 28, 2008 09:57 PM|ritvikd|LINK
I believe you are using VB.NET language.
ByVal stands for By Value rather than By Reference.
System.Object and System.EventArgs are type of Objects System class provides.
sender is an instance of System.Object, e is instance of System.EventArgs
By default during click event the .NET framework sends these two objects to the method.
I hope this answers your query.