problem while inheriting a UserControl base

Discussion in 'ASP .Net' started by SpaceMarine, Oct 4, 2008.

  1. SpaceMarine

    SpaceMarine Guest

    hello,

    i am working on a web application w/ UserControls. some of my controls
    use the same functionality (an Event they all raise) so it seemed
    sensible to place them into a custom base class, and have my
    UserControls inherit it.

    problem is, when i do this the im no longer able to raise the event in
    deriving UserControls. it fails to compile, saying:

    The event 'SubNavControl.NavItemClicked' can only appear on the left
    hand side of += or -= (except when used from within the type
    'SubNavControl')

    the code:

    SubNavControl.cs (base class):
    ----------------------------------------------------

    public class SubNavControl : UserControl
    {
    //delegate for nav-button clicks
    public delegate void NavItemClick(object sender, System.EventArgs
    e);

    //event for the same
    public event NavItemClick NavItemClicked;
    }



    SubNav.ascx.cs (deriving class):
    ----------------------------------------------------

    public partial class SubNav : SubNavControl
    {
    protected void imgSection1_Click(object sender, ImageClickEventArgs
    e)
    {
    //raise the event defined in base -- FAILS. works if delegate/
    event
    //is local only, not if in the base (see error message above)
    base.NavItemClicked(this, e);
    }

    }


    ....whats up? doing something wrong?

    thanks!
    sm
     
    SpaceMarine, Oct 4, 2008
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.