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

Discussion in 'ASP .Net' started by Bob, Mar 20, 2006.

  1. Bob

    Bob Guest

    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
     
    Bob, Mar 20, 2006
    #1
    1. Advertising

  2. Bob

    Teemu Keiski Guest

    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


    "Bob" <> wrote in message
    news:%...
    > 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
    >
    >
     
    Teemu Keiski, Mar 20, 2006
    #2
    1. Advertising

  3. Bob

    Bob Guest

    Thanks

    "Teemu Keiski" <> wrote in message
    news:Odcg$...
    > 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
    >
    >
    > "Bob" <> wrote in message
    > news:%...
    > > 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
    > >
    > >

    >
    >
     
    Bob, Mar 20, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trevor Hartman

    (Object source, EventArgs e)

    Trevor Hartman, Jun 26, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    597
    Kevin Spencer
    Jun 26, 2003
  2. Showjumper
    Replies:
    2
    Views:
    1,858
    Showjumper
    Aug 2, 2003
  3. Marcin Zmyslowski

    Button1.PerformClick() problem

    Marcin Zmyslowski, Sep 2, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,980
    Marcin Zmyslowski
    Sep 5, 2005
  4. Jado
    Replies:
    0
    Views:
    144
  5. Jado
    Replies:
    0
    Views:
    119
Loading...

Share This Page