2011-07-04 28 views
1

我宣佈我的用戶控件在用戶控件asp.net中聲明事件?

public event EventHandler<AddressEventArgs> SaveButtonClick; 

protected void ButtonSave_Click(object sender, EventArgs e) 
{ 
    if (SaveButtonClick != null) 
    { 
    SaveButtonClick(this, new AddressEventArgs) ; 

    } 
} 

後,我已經添加了用戶控制到新的頁面時,我將如何捕獲 事件由用戶控制提高嗎?

回答

4

要麼你可以[Browsable]財產上的事件,或者你可以命令式地綁定到事件。

userControl.SaveButtonClick += new EventHandler(handlerFunctionName); 

public void handlerFunctionName(AddressEventArgs args) 
{ 
    // Here, you have access to args in response the the event of your user control 
} 
+0

感謝saeed。你可以給我一些[browsable]屬性的見解。 –

+0

瀏覽的屬性只是意味着該屬性/事件應該在設計時環境進入。它們是屬性窗口,標記和代碼隱藏。 –

0
Control.SaveButtonClick += controlClicked; 

protected void controlClicked(object sender, EventArgs e) 
{ 
    //Do work 
} 

首先你需要訂閱你的事件,並給它一個方法來調用事件引發。