Events and Delegates

Discussion in 'ASP .Net Building Controls' started by Michael Morse, Feb 11, 2004.

  1. How in a asp.net web form can you have two different objects events call the
    same sub with different signatures.

    Example:
    I have 1 ImageButton control and 1 LinkButton

    Sub HandleTheEvent(ByVal sender as object, Byval e as eventArgs)
    'blah
    End Sub

    By doing
    AddHandler ImageButton1.Click, AddressOff Me.HandleTheEvent and
    AddHandler LinkButton1.Click, AddressOff Me.HandleTheEvent

    The signatures do not match up which is understandable. But what do I need
    to do to make this work.

    Thanks,

    -mike
     
    Michael Morse, Feb 11, 2004
    #1
    1. Advertising

  2. Hi Michael,

    Thank you for posting in the community!

    Based on my understanding, you have 2 web controls on the web form, 1 is a
    normal button control, the other is an imagebutton. You want to use the
    same event handler for these 2 buttons' click event.

    =========================================
    Actually, the Button's click event takes the normal EventHandler class,
    while the ImageButton click event use the ImageClickEventHandler.
    They take different EventArgs parameters. This is by the design of the C#
    language. So you can not do like this.(I see you already understand this
    point)

    I think your 2 buttons(Button and ImageButton) may have the same click
    handle logic, so you want to use the same event handler for them.

    I think you can place the common click handle logic into a private method,
    then use 2 different event handlers for each click event.
    In both event handler, you can invoke this private method, then it will
    behave the same as what you want.

    Actually, for ImageButton's click event, .Net expose more feature for the
    user to use, so it uses ImageClickEventHandler for its click event. This
    event handler takes ImageClickEventArgs parameter, which has 2 more fields
    "X" and "Y" to represent the coordinates where a user clicked on an
    image-based ASP.NET server control.

    That's why .Net expose 2 different event handlers for these 2 Buttons.

    ========================================
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.
    Have a nice day!!

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Feb 12, 2004
    #2
    1. Advertising

  3. Yeah that's what I have done in the meantime. I just wasn't sure I if I
    could override the signature or do something that I just haven''t thought of
    or new about.

    Thanks

    -mike


    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi Michael,
    >
    > Thank you for posting in the community!
    >
    > Based on my understanding, you have 2 web controls on the web form, 1 is a
    > normal button control, the other is an imagebutton. You want to use the
    > same event handler for these 2 buttons' click event.
    >
    > =========================================
    > Actually, the Button's click event takes the normal EventHandler class,
    > while the ImageButton click event use the ImageClickEventHandler.
    > They take different EventArgs parameters. This is by the design of the C#
    > language. So you can not do like this.(I see you already understand this
    > point)
    >
    > I think your 2 buttons(Button and ImageButton) may have the same click
    > handle logic, so you want to use the same event handler for them.
    >
    > I think you can place the common click handle logic into a private method,
    > then use 2 different event handlers for each click event.
    > In both event handler, you can invoke this private method, then it will
    > behave the same as what you want.
    >
    > Actually, for ImageButton's click event, .Net expose more feature for the
    > user to use, so it uses ImageClickEventHandler for its click event. This
    > event handler takes ImageClickEventArgs parameter, which has 2 more fields
    > "X" and "Y" to represent the coordinates where a user clicked on an
    > image-based ASP.NET server control.
    >
    > That's why .Net expose 2 different event handlers for these 2 Buttons.
    >
    > ========================================
    > Please apply my suggestion above and let me know if it helps resolve your
    > problem.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    > Have a nice day!!
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
     
    Michael Morse, Feb 12, 2004
    #3
  4. Hi Michael,

    Thanks very much for your feedback.

    I see your concern of original post :).

    If you have any further questions, please feel free to post, I will help
    you.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Feb 13, 2004
    #4
    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. Gopal Prabhakaran

    Differnece between Events and Delegates

    Gopal Prabhakaran, Jan 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    7,155
    Gaurav Khanna [C# MVP]
    Jan 28, 2004
  2. bredal Jensen

    Events and delegates.

    bredal Jensen, Apr 29, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    415
    bredal Jensen
    Apr 30, 2004
  3. Veronica Jacobs

    Events and Delegates

    Veronica Jacobs, Jun 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    394
    John Saunders
    Jun 2, 2004
  4. Replies:
    5
    Views:
    381
  5. Vinki
    Replies:
    2
    Views:
    331
    Patrice
    Dec 23, 2009
Loading...

Share This Page