Public Sub CommonEventHander (sender as object, e as eventargs) Handles
button1.click, button2.click, button3.click
'Let's assume that web form button controls are what this event handler
handles
dim testButton as system.web.ui.button
'It's safe to cast sender as a system.web.ui.button because we know that
this is the only type of control this sub handles
testButton = CType(sender, system.web.ui.button)
'Check some property of the button that will identify it uniquely
'In this case, we'll use its name since all controls must have a unique
name
Select Case testButton.name
Case "btnItem1"
'Now that you know "btnItem1" was clicked, do whatever you need
to
Case "btnItem2"
'Now that you know "btnItem2" was clicked, do whatever you need
to
Case "btnItem3"
'Now that you know "btnItem3" was clicked, do whatever you need
to
End Select
End Sub
James McGivney said:
I'd like to ask one more related question. From this thread I have
learned how to detect which button was clicked and how to use this
information to change the properties of the button. But, suppose I find out
the 5th button was pressed, now how to I add an image to my 5th ImageButton.
Assume that the clicked button is Button5 and the imageButton I want to
change is ImageButton5. How do I get the info for imageButton5 ? VB6's
index property would make this simple. How do I accomplish this in C#.net ?