473,407 Members | 2,546 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,407 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 6002
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,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.