C# 已调用ASP.NET事件,但引发错误
这就是我的C# 已调用ASP.NET事件,但引发错误,c#,asp.net,events,C#,Asp.net,Events,这就是我的LoginControl类的外观: namespace WebApplication3 { public partial class LoginControl : System.Web.UI.UserControl { public event EventHandler ButtonLoginClick; protected void Page_Load(object sender, EventArgs e) {
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>
当我单击login按钮时,事件不会被触发,因为我收到以下错误
对象没有实例化
我想这是在谈论这件事。该错误恰好发生在我调用事件
按钮单击时 在页面上,您需要将ButtonLoginClick=“btnLogin\u Click”
更改为OnButtonLoginClick=“btnLogin\u Click”
然后asp.net会将您的处理程序绑定到LoginControl
事件。您好,谢谢。但是我怎么做得好呢?我尝试了页面加载:ButtonLoginClick=newEventHandler();但它需要更多的参数有错吗?点击并点击1