我想从用户控件调用一个方法到 aspx 页面
我正在尝试,但我无法在 aspx 页面中调用该方法
代码:
AddVisaUserControl.ascx.cs
public event EventHandler UserControlButtonClicked;
public void OnUserControlButtonClick()
{
if (UserControlButtonClicked != null)
{
UserControlButtonClicked(this,EventArgs.Empty);
}
}
protected void btnRemove_Click(object sender, EventArgs e)
{
OnUserControlButtonClick();
}
.aspx
编辑
在页面加载时的以下代码中,我收到“空引用错误”
AddVisaControl av;
protected void Page_Load(object sender, EventArgs e)
{
av.UserControlButtonClicked += new
EventHandler(AddVisaUserControl_UserControlButtonClicked);
}
private void AddVisaControl_UserControlButtonClicked(object sender, EventArgs e)
{
var ctrl = (AddVisaControl)LoadControl(@"AddVisaControl.ascx");
//ctrl.ID = i;
this.rpt1.Controls.Remove(ctrl);
}
有任何想法吗?提前致谢