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
| 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 Search this Thread Display Modes
  #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


}




 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
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



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


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