国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.net組件編程中的兩種事件編寫方法

2024-07-10 12:57:08
字體:
來源:轉載
供稿:網友
以下是組件代碼:
using system;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;

namespace nseventstudy
{
public delegate void twoeventhandle(int flag);

public class eventstudy : system.web.ui.webcontrols.webcontrol
{

///////////////第一種定義事件的方法////////////////////

public event twoeventhandle twoevent;

public void execute(int flag)
{
twoevent(flag);
}

////////////////第二種定義事件的方法////////////////////

private static 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("我愛你,中國");
}

}
}


測試程序:
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;
using system.web.ui.htmlcontrols;

namespace testevent
{
/// <summary>
/// webform1 的摘要說明。
/// </summary>
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)
{
// 在此處放置用戶代碼以初始化頁面
}

#region web 窗體設計器生成的代碼
override protected void oninit(eventargs e)
{
//
// codegen: 該調用是 asp.net web 窗體設計器所必需的。
//
initializecomponent();
base.oninit(e);
}

/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
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("<script>javascript:alert('twoevent事件觸發')</script>");
}

private void eventstudy1_threeevent(int flag)
{
this.response.write("<script>javascript:alert('threeevent事件觸發')</script>");
}

private void button1_click(object sender, system.eventargs e)
{
this.eventstudy1.execute(6);
this.eventstudy1.innerexecute(10);
}
}
}



最大的網站源碼資源下載站,

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湾仔区| 沿河| 商河县| 固镇县| 哈尔滨市| 民县| 科技| 敖汉旗| 安国市| 康乐县| 广安市| 云浮市| 青浦区| 乌拉特前旗| 平阳县| 尚志市| 香港 | 乳源| 旺苍县| 郧西县| 双城市| 康马县| 富顺县| 福鼎市| 渭南市| 新河县| 微山县| 辽阳市| 成武县| 田东县| 保山市| 伊宁县| 齐齐哈尔市| 什邡市| 克东县| 沂南县| 蕉岭县| 梁平县| 瓦房店市| 宾阳县| 临澧县|