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

Hello,

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?

Regards,
Martin
-------
************************************************** **********************


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



    public class TestControl : WebControl, IPostBackDataHandler, IPostBackEventHandler
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]


        // ----------------------------------------------
        // 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")
            {
                this.Value++;

                EventArgs e = new EventArgs();
                OnMyEvent(EventArgs.Empty);
            }
            else
            {
                this.Value--;
            }
        }
        // ----------------------------------------

        protected override void OnInit(EventArgs e)
        {
            Page.RegisterRequiresPostBack(this);


        }
        // ---------------------------------------


        ...

    } // 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.