我有一个简单的用户控件,其中包含一些按钮,这些按钮触发事件,我希望页面使用控件来处理这些事件。我的代码设置如下:
public event EventHandler Cancel;
public event EventHandler Confirm;
public void Confirm_Click(object sender, EventArgs e)
{
if (Confirm != null)
Confirm(this, e);
}
public void Cancel_Click(object sender, EventArgs e)
{
if (Cancel != null)
Cancel(this, e);
}
但当我尝试从使用控件的页面的页面加载事件调用它们时,我没有得到任何自定义事件。
ASPX代码
<%@ Register TagPrefix="btg" TagName="CustomControl" Src="~/Search/CustomControl.ascx" %>
<btg:CustomControl ID="btgControl" runat="server" ></btg:CustomControl>
这可能是因为您的用户控件中的按钮位于更新面板内吗?