自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ASP.NET組件編程之事件編寫淺析

開發(fā) 后端
ASP.NET組件編程中事件編寫的方法是什么呢?本問就向你介紹兩種ASP.NET組件編程的事件編寫方法。

ASP.NET組件編程之事件編寫是如何的呢?那么我們首先來看看ASP.NET組件的應(yīng)用:

ASP.NET組件編程之組件代碼:

  1. using System;   
  2. using System.Web.UI;   
  3. using System.Web.UI.WebControls;   
  4. using System.ComponentModel;   
  5.  
  6. namespace NSEventStudy   
  7. {   
  8. public delegate void TwoEventHandle(int flag);   
  9.  
  10. public class EventStudy : System.Web.UI.WebControls.WebControl   
  11. {   
  12.  
  13. ///////////////ASP.NET組件編程***種定義事件的方法////////////////////   
  14.  
  15. public event TwoEventHandle TwoEvent;   
  16.  
  17. public void Execute(int flag)   
  18. {   
  19. TwoEvent(flag);   
  20. }   
  21.  
  22. ////////////////ASP.NET組件編程第二種定義事件的方法////////////////////   
  23.  
  24. private static object _Process = new object();   
  25. public event TwoEventHandle ThreeEvent   
  26. {   
  27. add   
  28. {   
  29. Events.AddHandler(_Process,value);   
  30. }   
  31. remove   
  32. {   
  33. Events.RemoveHandler(_Process,value);   
  34. }   
  35. }   
  36.  
  37. public void InnerExecute(int flag)   
  38. {   
  39. TwoEventHandle handle = (TwoEventHandle)Events[_Process];   
  40. if(handle != null)   
  41. {   
  42. handle(flag);   
  43. }   
  44. else   
  45. {   
  46. this.RaiseBubbleEvent(this,null);   
  47. }   
  48. }   
  49.  
  50. protected override void Render(HtmlTextWriter writer)   
  51. {   
  52. base.Render (writer);   
  53. writer.WriteLine("我愛你,中國");   
  54. }   
  55.  
  56. }   
  57. }  

ASP.NET組件編程之事件實(shí)現(xiàn)測試程序:

  1. using System;   
  2. using System.Collections;   
  3. using System.ComponentModel;   
  4. using System.Data;   
  5. using System.Drawing;   
  6. using System.Web;   
  7. using System.Web.SessionState;   
  8. using System.Web.UI;   
  9. using System.Web.UI.WebControls;   
  10. using System.Web.UI.HtmlControls;   
  11.  
  12. namespace TestEvent   
  13. {   
  14. /// ﹤summary﹥   
  15. /// WebForm1 的摘要說明。   
  16. /// ﹤/summary﹥   
  17. public class WebForm1 : System.Web.UI.Page   
  18. {   
  19. protected System.Web.UI.WebControls.Button Button1;   
  20. protected NSEventStudy.EventStudy EventStudy1;   
  21.  
  22. private void Page_Load(object sender, System.EventArgs e)   
  23. {   
  24. // 在此處放置用戶代碼以初始化頁面   
  25. }   
  26.  
  27. #region Web 窗體設(shè)計(jì)器生成的代碼   
  28. override protected void OnInit(EventArgs e)   
  29. {   
  30. //   
  31. // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。   
  32. //   
  33. InitializeComponent();   
  34. base.OnInit(e);   
  35. }   
  36.  
  37. /// ﹤summary﹥   
  38. /// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改   
  39. /// 此方法的內(nèi)容。   
  40. /// ﹤/summary﹥   
  41. private void InitializeComponent()   
  42. {   
  43. this.EventStudy1.ThreeEvent += new NSEventStudy.TwoEventHandle(this.EventStudy1_ThreeEvent);   
  44. this.EventStudy1.TwoEvent += new NSEventStudy.TwoEventHandle(this.EventStudy1_TwoEvent);   
  45. this.Button1.Click += new System.EventHandler(this.Button1_Click);   
  46. this.Load += new System.EventHandler(this.Page_Load);   
  47.  
  48. }   
  49. #endregion   
  50.  
  51. private void EventStudy1_TwoEvent(int flag)   
  52. {   
  53. this.Response.Write("﹤script﹥javascript:alert('TwoEvent事件觸發(fā)')﹤/script﹥");   
  54. }   
  55.  
  56. private void EventStudy1_ThreeEvent(int flag)   
  57. {   
  58. this.Response.Write("﹤script﹥javascript:alert('ThreeEvent事件觸發(fā)')﹤/script﹥");   
  59. }   
  60.  
  61. private void Button1_Click(object sender, System.EventArgs e)   
  62. {   
  63. this.EventStudy1.Execute(6);   
  64. this.EventStudy1.InnerExecute(10);   
  65. }   
  66. }   

ASP.NET組件編程中事件的編寫實(shí)現(xiàn)就向你介紹到這里,希望對你有所幫助。

【編輯推薦】

  1. ASP.NET服務(wù)器控件視圖淺析
  2. ASP.NET組件設(shè)計(jì)之生命周期詳解
  3. ASP.NET組件設(shè)計(jì)之傳輸機(jī)制淺析
  4. ASP.NET組件設(shè)計(jì)之復(fù)雜屬性和狀態(tài)管理淺析
  5. ASP.NET httpHandler使用淺析
責(zé)任編輯:仲衡 來源: 教程在線
相關(guān)推薦

2009-08-06 13:08:23

ASP.NET控件開發(fā)

2009-08-10 15:42:33

ASP.NET Che

2009-08-10 16:07:44

ASP.NET Lin

2009-08-05 16:53:14

ASP.NET組件設(shè)計(jì)

2009-07-24 18:02:46

ASP.NET編程

2009-08-10 13:32:15

ASP.NET TimASP.NET組件設(shè)計(jì)

2009-07-27 14:29:31

ASP.NET編程彈窗報(bào)警提示

2009-09-09 12:35:00

ASP.NET回車提交回車提交事件

2009-08-03 13:38:18

ASP.NET編程模型

2009-07-22 17:45:35

ASP.NET教程

2009-08-05 16:59:55

ASP.NET組件設(shè)計(jì)

2009-08-03 13:12:34

ASP.NET編程模型

2009-07-27 13:34:15

ASP.NET編程

2009-07-24 13:41:15

ASP.NET AJA

2009-08-05 18:36:12

ASP.NET Che

2009-07-31 12:43:59

ASP.NET MVC

2009-08-05 15:50:13

ASP.NET優(yōu)點(diǎn)

2009-08-10 14:38:29

ASP.NET組件設(shè)計(jì)

2009-08-03 18:00:00

ASP.NET服務(wù)器控

2009-08-03 11:21:47

ASP.NET編程模型
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)