Two incident writing methods in ASP.NET component programming

xiaoxiao2021-03-06  14

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 {///

/// WebForm1. /// public class WebForm1: System.Web.UI.Page {protected System.Web.UI.WebControls.Button Button1; protected NSEventStudy.EventStudy EventStudy1; private void Page_Load (object sender, System.EventArgs e) { / / Place the user code here to initialize the page}

#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);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.EventStudy1.ThreeEvent = new NSEventStudy.TwoEventHandle (this.EventStudy1_ThreeEvent); this.EventStudy1.TwoEvent = new NSEventStudy.TwoEventHandle (this.EventStudy1_TwoEvent); this.Button1 .Click = new system.EventHandler (this.button1_click; this.load = new system.eventhandler (this.page_load);} #ENDREGION

Private void eventstudy1_twoevent (int flag) {this.response.write ("