Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Events and Delegates

Reply
Thread Tools

Events and Delegates

 
 
Michael Morse
Guest
Posts: n/a
 
      02-11-2004
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



 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      02-12-2004

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.

 
Reply With Quote
 
 
 
 
Michael Morse
Guest
Posts: n/a
 
      02-12-2004
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]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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.
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      02-13-2004

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
events and delegates for a treview control Vinki ASP .Net 2 12-23-2009 08:35 PM
Delegates, Events and the Page Lifecycle studio60podcast@gmail.com ASP .Net 5 04-19-2007 06:46 PM
Events and Delegates Veronica Jacobs ASP .Net 1 06-02-2004 09:17 AM
Events and delegates. bredal Jensen ASP .Net 7 04-30-2004 08:04 AM
Differnece between Events and Delegates Gopal Prabhakaran ASP .Net 2 01-28-2004 05:13 AM



Advertisments