Export (0) Print
Expand All

Troubleshooting Inherited Event Handlers in Visual Basic .NET

This topic lists common issues that arise with event handlers in inherited components. For more information, see Overriding Event Handlers with Visual Basic .NET.

Code in Event Handler Executes Twice for Every Call

  • An inherited event handler must not include a Handles clause. The method in the base class is already associated with the event and will fire accordingly. Remove the Handles clause from the inherited method.
    ' INCORRECT
    Protected Overrides Sub Button1_Click(ByVal sender As System.Object, _
       ByVal e as System.EventArgs) Handles Button1.Click
       ' The Handles clause will cause all code
       ' in this block to be executed twice.
    End Sub
    
    ' Visual Basic
    Protected Overrides Sub Button1_Click(ByVal sender As System.Object, _
       ByVal e as System.EventArgs)
       ' Insert code to do something here.
    End Sub
    
  • If the inherited method does not have a Handles keyword, verify that your code does not contain an extra AddHandler Statement or any additional methods that handle the same event.

See Also

Writing Event Handlers | Events and Event Handlers | Event Handler Example | Events and Delegates

Show:
© 2015 Microsoft