Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-07-21
3
Medium Priority
?
807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

721 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