events inheritance

Discussion in 'ASP .Net Web Controls' started by Arturo Buonanni, Apr 4, 2006.

  1. 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.
     
    Arturo Buonanni, Apr 4, 2006
    #1
    1. Advertising

  2. Arturo Buonanni

    Guest

    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
     
    , Apr 4, 2006
    #2
    1. Advertising

  3. Thanks for your reply.

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

    Am I right?

    On 4 Apr 2006 08:23:42 -0700, ""
    <> wrote:

    >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
     
    Arturo Buonanni, Apr 5, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,152
    Martijn van Steenbergen
    Dec 21, 2003
  2. cppsks
    Replies:
    0
    Views:
    827
    cppsks
    Oct 27, 2004
  3. karthikbalaguru
    Replies:
    9
    Views:
    1,045
  4. Daniel Pitts
    Replies:
    27
    Views:
    1,913
    Mike Schilling
    Feb 27, 2008
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    380
    Chris
    Aug 30, 2005
Loading...

Share This Page