我需要在類構造函數中添加事件(鼠標點擊)的建議。建議在對象構造函數中添加事件
我有一組圖像,我從Flickr獲得,可以改變,我想添加到他們的點擊事件。
我真的有一個問題,所以我做了一個類圖像,並在構造函數中添加事件,所以我不需要搜索每次點擊他時我在頁面上單擊的控件。
這裏是構造的示例:
public FlickerImages(string url, string title, string desc, System.Web.UI.Page page,ImageButton image)
{
this.url = url;
this.title = title;
this.descreption = desc;
this.image = image;
image.Click += this.onImageClick; //--> the event
//image is a ImageButton object
this.page = page;
}
我想知道,如果這是一個很好的做法,或者我應該經常添加的對象類之外的事件?
(對不起我的英語)
@TimSchmelter它只是一個小測試,我希望看到結果快,所以我引用了頁面和你的page.Response.Write(「」)方法。 – samy 2012-02-27 11:11:38