Export (0) Print
Expand All

Control.Events Property

Gets a list of event handler delegates for the control. This property is read-only.

[Visual Basic]
Protected ReadOnly Property Events As EventHandlerList
[C#]
protected EventHandlerList Events {get;}
[C++]
protected: __property EventHandlerList* get_Events();
[JScript]
protected function get Events() : EventHandlerList;

Property Value

The list of event handler delegates.

Remarks

This property is of type EventHandlerList, which uses a linear search algorithm to find entries in the list of delegates. A linear search algorithm is inefficient when working with a large number of entries. Therefore, when you have a large list, finding entries with this property will be slow.

Example

The following example creates an event, named Click, that adds and removes handlers from the control's EventHandlerList collection when the event is called from a page.

Note   This example optimizes how a control adds and removes events from the list of them that the control maintains. If you create custom control and want to define an event, use code similar to this. This technique can be use in C#, but not in Visual Basic .NET.
[SampleID='System.Web.UI.Page_VerifyRenderingInServerForm' SnippetID='1']
--------- Languages displayed= cs ---------
--------- cs ---------
--------- Snippet 1 ---------
        // Create an event that adds and removes handlers from the
        // Control.Events collection when this event is called from
        // a participating page.
        public event EventHandler Click {
            add {
                Events.AddHandler(EventClick, value);
            }
            remove {
                Events.RemoveHandler(EventClick, value);
            }
   }

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | EventHandlerList

Show:
© 2014 Microsoft