Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 已调用ASP.NET事件,但引发错误_C#_Asp.net_Events - Fatal编程技术网

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