Can't find an Event Handler

  • Thread starter Thread starter Ken Kast
  • Start date Start date
K

Ken Kast

What I'm trying to do is find a way to determine at run time if a particular
event handler in a UserControl has been defined. Here's a snippet of code:

Public Event Button_Click As EventHandler

Public WriteOnly Property ButtonClick() As System.EventHandler

Set(ByVal Value As System.EventHandler)

If Not Value Is Nothing Then

AddHandler Me.Button_Click, Value

Me.HasButtonClick = True

End If

Console.WriteLine("Handler exists=" & Not (Me.Events(Me.Button_ClickEvent)
Is Nothing))

End Set



The write statement prints out False, but the handler is in fact installed,
i.e., the event is handled by the event handler passed in is executed. Why
doesn't the Events list show the handler?



Ken
 
I saw the Google posting and actually tried it first. I exception off
because GetInvocationList is Nothing (which I assume is equivalent to my not
finding the handler in Events). So I'm looking to solve one or the other of
the puzzles.

Ken
 
Still don't know what the problem is with using the handler list but I
solved my particular problem (how to find out if a handler exists) by making
the test

Not (Me.Button_ClickEvent Is Nothing)

Ken
 
Back
Top