2011-07-04 2 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

[browsable] 속성에 대한 통찰력을 제공 할 수 있습니다. –

+0

Browsable 속성은 단순히이 특성/이벤트가 디자인 타임 환경에서 액세스 가능해야 함을 의미합니다. 속성 창, 마크 업 및 코드 숨김입니다. –

0
Control.SaveButtonClick += controlClicked; 

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

먼저 이벤트에 가입하고 이벤트 발생시 전화 할 방법을 제공해야합니다.

관련 문제