Get name of 'sender' in vb (asp) click event

I have an ASPX web page with VB code behind, there are 2 asp buttons in the page both being handled by the same event handler, which is...

 Protected Sub cmdPrint_Click(sender As Object, e As EventArgs) Handles cmdPrint.Click, cmdReprint.Click

Open in new window


How can I get the name of which of the two buttons was clicked? I have tried the following different methods but I always get the same error 'System.InvalidCastException'

Dim buttonClicked As Button = sender
or
Dim buttonClicked As Button = CType(sender, Button)
or
Dim buttonClicked As Button = DirectCast(sender, Button)

much Googling tells me either of these should work, but none of them do,

what am I missing?
BrianFordAsked:
Who is Participating?
 
Randy PooleCommented:
Dim clickedButton As Button = sender
should work
0
 
BrianFordAuthor Commented:
actually I just realized my embarrassing mistake, the controls are 'LinkButtons' not 'Buttons' so the casting error makes perfect sense, duh!

thanks for your response anyway :-)
0
 
Randy PooleCommented:
lol no problem :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.