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

标签 c# asp.net visual-studio

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

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
}

关于c# - 在用户控件 asp.net 中声明事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6574569/

相关文章:

c# - 嵌套的 DataContract 序列化异常 WCF

c# - 静态类中的函数需要调用类的名称

asp.net - WinDBG 中 !clrstack 命令的输出中 GCFrame 是什么意思?

c# - 使用 LINQ 基于三列搜索全名

visual-studio - 如何将其他测试项目添加到 Visual Studio 2015 中的 "Create Unit Tests"上下文菜单?

c# - PropertyInfo.GetValue(object) 因 IEnumerable<T> [C#, Reflection] 而失败

c# - 哪种设计模式用于灵活的消息发送?

javascript - Response.Redirect 和 OnBeforeUnload 可以很好地协同工作吗?

c# - AppHarbor 预编译错误

.net - 如何在多项目 sln 模板 Visual Studio 2015 中添加现有项目