【发布时间】:2018-10-26 04:45:57
【问题描述】:
这就是我的LoginControl 类的样子:
namespace WebApplication3
{
public partial class LoginControl : System.Web.UI.UserControl
{
public event EventHandler ButtonLoginClick;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click1(object sender, EventArgs e)
{
ButtonLoginClick(sender, e);
}
}
}
在我使用控件的页面上,我有以下代码:
<myComps:LoginControl runat="server" ID="LoginControl" ButtonLoginClick="btnLogin_Click"></myComps:LoginControl>
当我点击登录按钮时,没有触发该事件,因为我收到以下错误
一个对象没有被实例化。
我猜它是在谈论事件。错误发生在我调用事件ButtonLoginClick 时。
【问题讨论】:
-
嗨,谢谢。但是我做得对吗?我在 page_load 中尝试过: ButtonLoginClick = new EventHandler();但它需要更多参数
-
有错字吗? btnLogin_click 和 btnLogin_click1