Wrox Programmer Forums
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 February 23rd, 2007, 06:31 AM
Registered User
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom event not firing


I have a problem with custom controls and raising events (asp.net, vs2005, frameowork 2.0).
I am making a simple TestControl to learn how custom controls work.
Most things went fine, but now I ran into a problem that
a custom event is not fired. See code piece below.
I have commented the lines that cause the problem.

Problem: for some reason, the event-declaration is not executed,
so 'MyEvent' is always null, and thus the event is not fired.
But the question is: why is the declaration not executed (why is 'MyEvent' is always null)
and what can I do about it?

Can anybody help me please?

************************************************** **********************

namespace TestControl
    [ToolboxData("<{0}:TestControl runat=server></{0}:TestControl>")]

    public class TestControl : WebControl, IPostBackDataHandler, IPostBackEventHandler

        // ----------------------------------------------
        // Declare delegate for event
        public delegate void EventDelegate (Object sender, EventArgs e);
        public event EventDelegate MyEvent; // *** This line is not executed. why?

        protected virtual void OnMyEvent(EventArgs e)
            if (MyEvent != null) MyEvent(this, e); // *** here, MyEvent is null. Why?

        // ----------------------------------------------
        public void RaisePostBackEvent(String eventArgument)

            if (eventArgument == "Add")

                EventArgs e = new EventArgs();
        // ----------------------------------------

        protected override void OnInit(EventArgs e)

        // ---------------------------------------


    } // end of classs


Similar Threads
Thread Thread Starter Forum Replies Last Post
selectedindexchanged event not firing kaliaparijat ASP.NET 2.0 Professional 1 June 5th, 2008 08:58 AM
Event Firing tobriain C# 1 June 12th, 2007 08:19 AM
onSelectedIndexChanged event not firing??? MTLedari ASP.NET 2.0 Basics 5 December 19th, 2006 10:35 AM
OnSelectedIndexChanged event not firing ethertt77 ASP.NET 2.0 Basics 2 February 20th, 2006 07:34 PM
Session_Start event not firing.. (not Sharepoint) Koroshiya ASP.NET 1.0 and 1.1 Professional 10 February 25th, 2005 05:35 PM

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