Solved

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

Posted on 2014-07-21
3
707 Views
Last Modified: 2014-07-21
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
Comment
Question by:BrianFord
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40209724
Dim clickedButton As Button = sender
should work
0
 

Author Closing Comment

by:BrianFord
ID: 40209735
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
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40209736
lol no problem :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question