|
-
Jul 2nd, 2003, 01:08 PM
#1
Thread Starter
Fanatic Member
User Control Inheritance and Overriden procedures
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:
Public Class ControlBase
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
OnBeforeSave()
OnSave()
OnAfterSave()
End Sub
Protected Overridable Sub OnSave()
'
End Sub
Protected Overridable Sub OnBeforeSave()
'
End Sub
Protected Overridable Sub OnAfterSave()
'
End Sub
End Class
Public Class ExtendedControl
Inherits WindowsApplication3.ControlBase
#Region " Windows Form Designer generated code "
Protected Overrides Sub OnAfterSave()
MyBase.OnAfterSave()
MsgBox("hello world from onaftersave")
End Sub
Protected Overrides Sub OnBeforeSave()
MyBase.OnBeforeSave()
MsgBox("hello world from onbeforesave")
End Sub
Protected Overrides Sub OnSave()
MyBase.OnSave()
MsgBox("hello world from onsave")
End Sub
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
-
Jul 2nd, 2003, 01:30 PM
#2
I haven't noticed any problems yet. That is wierd. Is it always the same method that does act right? If so maybe its something related to that event specifically.
-
Jul 2nd, 2003, 01:55 PM
#3
Thread Starter
Fanatic Member
It seems to be that one procedure, but on many inherited user controls.
-
Jul 2nd, 2003, 02:54 PM
#4
Maybe the parent class is calling it via its own MyBase call or something and thus skipping it. Does that one always not work? Or does that method sometimes work?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|