Link to home
Start Free TrialLog in
Avatar of BrianFord
BrianFordFlag for United States of America

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of Randy Poole
Randy Poole
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrianFord

ASKER

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 :-)
lol no problem :)