Sub button1(Source As Object, e As EventArgs)??

B

Bob

Hi,

I'm still new to asp.net and i would like to understand this: "Source As
Object, e As EventArgs"

<script runat="server">
Sub button1(Source As Object, e As EventArgs)
p1.InnerHtml="You clicked the blue button!"
End Sub
</script>

Are the words 'source', 'object', 'e' and 'EventArgs' compelled? Is this the
right syntax for all 'onclick' events?
Thanks
Bob
 
T

Teemu Keiski

Hi,

it is basically standard in .NET that signature of an event handler method
consists of 'sender' argument and event argument type 'EventArgs' which
exposes optional event arguments. 'sender' represents the object which
raised the event in question. Object and EventArgs are types and they matter
with what is expected to be the signature of the event handler method.
Evenht can also declare a more specific type, deriving from EventArgs, to be
the event argument type however 'senbder' is always of type object.

So you could also have signature like this

Sub button1(Source As Object, e As EventArgs)

or

Sub button1(sender As Object, args As EventArgs)

or

Sub button1(sender As Object, e As EventArgs)

or

Sub button1(obj As Object, e As EventArgs)

....

e.g you can name the incoming arguments yourself as long as their types
match with the signature enforced by the event (basically delegate).
However, this does not mean you couldn't create your own events with
different signature, this is just pattern followed in .NET Framework's class
libraries.

More information
============

Events And Delegates
http://msdn.microsoft.com/library/d...bcn7/html/vaconEventsDelegatesInheritance.asp

Design Guidelines for Class Library Developers -> Event Naming Guidelines
http://msdn.microsoft.com/library/d.../cpgenref/html/cpconeventnamingguidelines.asp

Design Guidelines for Class Library Developers -> Event Usage Guidelines
http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconeventusageguidelines.asp
 
B

Bob

Thanks

Teemu Keiski said:
Hi,

it is basically standard in .NET that signature of an event handler method
consists of 'sender' argument and event argument type 'EventArgs' which
exposes optional event arguments. 'sender' represents the object which
raised the event in question. Object and EventArgs are types and they matter
with what is expected to be the signature of the event handler method.
Evenht can also declare a more specific type, deriving from EventArgs, to be
the event argument type however 'senbder' is always of type object.

So you could also have signature like this

Sub button1(Source As Object, e As EventArgs)

or

Sub button1(sender As Object, args As EventArgs)

or

Sub button1(sender As Object, e As EventArgs)

or

Sub button1(obj As Object, e As EventArgs)

...

e.g you can name the incoming arguments yourself as long as their types
match with the signature enforced by the event (basically delegate).
However, this does not mean you couldn't create your own events with
different signature, this is just pattern followed in .NET Framework's class
libraries.

More information
============

Events And Delegates
http://msdn.microsoft.com/library/d...bcn7/html/vaconEventsDelegatesInheritance.asp

Design Guidelines for Class Library Developers -> Event Naming Guidelines
http://msdn.microsoft.com/library/d.../cpgenref/html/cpconeventnamingguidelines.asp

Design Guidelines for Class Library Developers -> Event Usage Guidelines
http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconeventusageguidelines.asp

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top