473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to get control identification from (Sender as Object)

Hi,

I have this event that is performed by three different controls, how can
I know (from sender object) wich control is used to trigger the event?

Private Sub HighlightSelectedRow(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tbxAmount.Click, lblID.Click, lblExpense.Click

Dim ctlControl As System.Type
ctlControl = sender.GetType

'???
Select Case ctlControl
'???
End Select

End Sub
Thanks

Marty
Jul 21 '05 #1
3 6000
You can use TypeOf and CType.

If TypeOf sender Is Label Then
Dim lbl As Label = CType(sender, Label)
Select Case lbl.Name
Case Is = "lblID"
' do something
Case Is = "lblExpense"
' do something
End Select
ElseIf TypeOf sender Is TextBox Then
Dim txt As TextBox = CType(sender, TextBox)
' do something
End If

"Marty" <xm******@hotmail.com> wrote in message
news:tI**************@fe51.usenetserver.com...
Hi,

I have this event that is performed by three different controls, how can I
know (from sender object) wich control is used to trigger the event?

Private Sub HighlightSelectedRow(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tbxAmount.Click, lblID.Click, lblExpense.Click

Dim ctlControl As System.Type
ctlControl = sender.GetType

'???
Select Case ctlControl
'???
End Select

End Sub
Thanks

Marty

Jul 21 '05 #2
Wonderful, thanks you!

Marty

Jared wrote:
You can use TypeOf and CType.

If TypeOf sender Is Label Then
Dim lbl As Label = CType(sender, Label)
Select Case lbl.Name
Case Is = "lblID"
' do something
Case Is = "lblExpense"
' do something
End Select
ElseIf TypeOf sender Is TextBox Then
Dim txt As TextBox = CType(sender, TextBox)
' do something
End If

"Marty" <xm******@hotmail.com> wrote in message
news:tI**************@fe51.usenetserver.com...
Hi,

I have this event that is performed by three different controls, how can I
know (from sender object) wich control is used to trigger the event?

Private Sub HighlightSelectedRow(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tbxAmount.Click, lblID.Click, lblExpense.Click

Dim ctlControl As System.Type
ctlControl = sender.GetType

'???
Select Case ctlControl
'???
End Select

End Sub
Thanks

Marty


Jul 21 '05 #3
Marty,
In addition to Jared,

Keep in mind that you do not have to know the type when the member is
inheritted from control.

They have by instance all name, text, click etc.

Cor
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: frankcvc | last post by:
I created a control array at runtime using the following code. I also wanted to code the controlarray click event. My code can respond to click event but cannot identify the specific control...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
6
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
9
by: Charles Law | last post by:
I have a form on which user controls are placed at runtime. When a control is added to the form a handler is added for an event that a high-level object raises, which must be handled by the new...
3
by: Marty | last post by:
Hi, I have this event that is performed by three different controls, how can I know (from sender object) wich control is used to trigger the event? Private Sub HighlightSelectedRow(ByVal...
2
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all...
4
by: Rich | last post by:
Hello, I have 3 textboxes and 1 combobox on a form. On entering the control I want to select all the text. I can make an array of textboxes like this: Dim arrTxt As TextBox() = {txt1, txt2,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.