Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 843
  • Last Modified:

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?
0
BrianFord
Asked:
BrianFord
  • 2
1 Solution
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now