Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Troubleshooting Inherited Event Handlers in Visual Basic

This topic lists common issues that arise with event handlers in inherited components.

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
    
    ' 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
    
  • 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.

Community Additions

ADD
Show:
© 2015 Microsoft