[英]Declaring event in user control asp.net?
我已經在我的用戶控件上聲明了一個事件
public event EventHandler<AddressEventArgs> SaveButtonClick;
protected void ButtonSave_Click(object sender, EventArgs e)
{
if (SaveButtonClick != null)
{
SaveButtonClick(this, new AddressEventArgs) ;
}
}
將用戶控件添加到新頁面后,如何捕獲用戶控件引發的事件?
您可以在事件上使用[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
}
Control.SaveButtonClick += controlClicked;
protected void controlClicked(object sender, EventArgs e)
{
//Do work
}
首先,您需要訂閱您的事件,並為其提供一個在引發事件時調用的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.