Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 1st, 2008, 07:31 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default Invoke Events that were declated in a super class

Hi,

I have a thin class which inherits from UserControl which only adds an event, as follows:
Code:
public class DynamicUserControl :UserControl
{
    public event EventHandler dynamicControlEvent;

}
Then I have a couple of user controls that inherit from that, i.e.
Code:
public partial class NewPageControl : DynamicUserControl
{
    protected void btnNewPageSubmit_Click(object sender, EventArgs e)
    {
        // package up the event and pass it on to the container
        if ( dynamicControlEvent != null )
            dynamicControlEvent(this, null);
    }
}
Trouble is, I get a compile error on the 2 lines at the bottom that attempt to fire the event that was declared in the superclass. Any idea why this is or how to get around it? Thanks.

Aaron



 
Old January 2nd, 2008, 03:59 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

And the error was??

A better way of doing this is to encapsulate the calling of the event in the super class:

public class DynamicUserControl :UserControl
{
    public event EventHandler dynamicControlEvent;

    protected void DoDynamicControlEvent(EventArgs e){
        // package up the event and pass it on to the container
        if ( dynamicControlEvent != null )
            dynamicControlEvent(this, null);
    }
}

Then call the protected method from the sub classes. This also centralizes the event handler state check so each subclass needn't perform it individually.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Raising COM Events in C# Class Library sreecareer ASP.NET 2.0 Basics 0 September 21st, 2008 08:50 PM
'super' keyword ?! nerssi Javascript 0 February 14th, 2008 08:17 AM
how to invoke the dll in ASP.NET 2.0 kanmani .NET Framework 2.0 0 January 15th, 2007 11:34 PM
Capturing toolbar events inside a dialog class pazzuzu Visual C++ 0 October 13th, 2004 01:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.