events inheritance

  • Thread starter Arturo Buonanni
  • Start date
A

Arturo Buonanni

Hello,

I'm writing a web app in wich I'm using some Web User Controls. Now I
want these controls to have some basic properties so I've defined my
own class that inherits from System.Web.UI.UserControl, defined some
properties and some code and made my actual Web User Controls inherits
from my class.

In my class I've also defined a public event but this event is not
available to the containers of the web user controls that inherits
from this class.

This is how my base user control class is defined:

<Serializable()> Public Class myContext
Public CurrentContext As String
Public Content As String
Public Description As String
Public Tag As Object
Public ParentContext As myContext

Public Sub New()
{...init here...}
End Sub
End Class

Public Class myUserControl
Inherits System.Web.UI.UserControl

Public mContext As New myContext
Public Event OnContextSetB(ByVal mCont As myContext)

Protected Sub SetContextA(ByVal mCont As myContext)
{...some code here...}
RaiseEvent OnContextSetB(mCont)
End Sub



Hope someone can help.

Thanks.
 
C

CaffieneRush

The subclass cannot raise baseclass' events.
http://msdn2.microsoft.com/en-US/library/0ecakwbz.aspx

But you should be able to handle the base class' events and so the
event is available in a sense.
'An example using your example code.
Public Class mySubUserControl
Inherits myUserControl

Public Sub OnSubSetB(mCont As myContext) Handles
MyBase.OnContextSetB
'Handle base class event here.
End Sub

'You can also handle base class' event by overriding the base
class' handler for that event - but that base handler will need to be
declared Overridable.
Protected Overrides Sub SetContextA(mCont As myContext)
'Handle base class event here.
End Sub

End Class
 
A

Arturo Buonanni

Thanks for your reply.

So to "Raise" my base class events I've to "bubble" them up through my
child class.

Am I right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top