Click to See Complete Forum and Search --> : Single Event handler for multiple linklabels
shabbu_1980
September 7th, 2005, 10:34 PM
Hi,
I have derived a class from linklabel class and created around multiple linklabels dynamically. The objects on these link labels are stored in an arraylist. I want to write a single event handler for all these links. How do i achieve this??
thanks and regards
jhammer
September 8th, 2005, 02:30 AM
First write the Event Handler (without the Handles clause):
Private Sub Generic_Label_Click(sender As Object, e As EventArgs)
Dim lbl As Label = CType(sender, Label) ' Cast to the label
'Do Whatever
End Sub
Now, when you create the label add a handler to the event using the AddHandler statement:
Dim lbl As New Label
Me.Controls.Add(lbl)
AddHandler lbl.Click, AddressOf(Generic_Label_Click)
I hope its clear
ambreesh
September 8th, 2005, 02:33 AM
Dim lbl As New Label
Me.Controls.Add(lbl)
AddHandler lbl.Click, AddressOf(Generic_Label_Click)
you could use a AddHandler lbl.command as well to make it work. remember the syntax is AddHandler Object as Event, Object as Delegate.
If you want to store key values within ur label you could use the commandarguments to do that. Let me know if u want to talk more about command arguments but as jhammer described it should solve ur problem.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.