Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 1st, 2008, 07:31 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: San Francisco, CA, USA.
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



  #2 (permalink)  
Old January 2nd, 2008, 03:59 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09: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 02:35 AM



All times are GMT -4. The time now is 06:07 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.