Skip to main content
 首页 » 编程设计

c#之在用户控件 asp.net 中声明事件

2024年02月23日13unruledboy

我已经在我的用户控件上声明了一个事件

public event EventHandler<AddressEventArgs> SaveButtonClick;  
 
protected void ButtonSave_Click(object sender, EventArgs e)  
{  
  if (SaveButtonClick != null)  
  {  
    SaveButtonClick(this, new AddressEventArgs) ;  
 
  }  
} 

在我将用户控件添加到新页面后,我将如何捕获 用户控件引发的事件?

请您参考如下方法:

您可以为事件设置 [Browsable] 属性,也可以强制绑定(bind)到事件。

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 
}