Two incident writing methods in ASP.NET component programming
The following is the component code: use system.Web.ui; use system.web.ui.webcontrols; using system.componentmodel;
Namespace NSEventStudy {Public Delegate Void TwoEventHandle (INT FLAG);
Public class eventstudy: system.web.ui.webControls.WebControl {/// First definition event method PUBLIC EVENT TWOEventHandle Twoevent;
Public Void Execute (int flag) {TwoEvent (flag);
Private static method defined in the second event object _Process = new object (); public event TwoEventHandle ThreeEvent {add {Events.AddHandler (_Process, value);} remove {Events.RemoveHandler (_Process, value);}}
Public void innerexecute (int flag) {TwoeventHandle Handle = (TwoEventHandle) Events [_Process]; if (Handle! = NULL) {Handle (flag);} else {this.raisebubbleEvent (this, null);}}
Protected Override Void Render (HTMLTextWriter Writer) {base.render (Writer); Writer.WriteLine ("I Love You, China");
}} Test procedure: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System. Web.ui.WebControls; use system.web.ui.htmlcontrols;
Summary description of Namespace TESTEVENT {///
#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///
Private void eventstudy1_twoevent (int flag) {this.response.write ("