Hi,

I have a ControlBase object which I am inheriting all of my user controls from and I have overriden a method in the extended user control. This overriden method runs fine most of the time, but every now and again, the application does not run the overriden procedure. It continues excecution as though the method was never overriden.

Here is an example

VB Code:
  1. Public Class ControlBase
  2.     Inherits System.Windows.Forms.UserControl
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  7.         OnBeforeSave()
  8.         OnSave()
  9.         OnAfterSave()
  10.     End Sub
  11.  
  12.     Protected Overridable Sub OnSave()
  13.         '
  14.     End Sub
  15.  
  16.     Protected Overridable Sub OnBeforeSave()
  17.         '
  18.     End Sub
  19.  
  20.     Protected Overridable Sub OnAfterSave()
  21.         '
  22.     End Sub
  23.  
  24. End Class
  25.  
  26. Public Class ExtendedControl
  27.     Inherits WindowsApplication3.ControlBase
  28.  
  29. #Region " Windows Form Designer generated code "
  30.  
  31.     Protected Overrides Sub OnAfterSave()
  32.         MyBase.OnAfterSave()
  33.         MsgBox("hello world from onaftersave")
  34.     End Sub
  35.  
  36.     Protected Overrides Sub OnBeforeSave()
  37.         MyBase.OnBeforeSave()
  38.         MsgBox("hello world from onbeforesave")
  39.     End Sub
  40.  
  41.     Protected Overrides Sub OnSave()
  42.         MyBase.OnSave()
  43.         MsgBox("hello world from onsave")
  44.     End Sub
  45. End Class

The excecution path looks like this:
ControlBase -> btnSave_Click
ExtendedControl -> OnBeforeSave
ControlBase -> OnBeforeSave
ControlBase -> OnSave
ExtendedControl -> OnAfterSave
ControlBase -> OnAfterSave

I thought I had done something wrong, but it sometimes runs the overriden code and sometimes not. Has anyone else had this problem or am I just smoking something?

Win2ksp3
.NET 2003
Framework V1.1.4322