简体   繁体   English

在asp.net页面中不包含按钮单击事件的定义错误

[英]Does not contain definition error for Button click event in asp.net page

i have a button in edit.aspx page with below code 我在edit.aspx页面中有一个带有以下代码的按钮

<asp:Button ID="GoButton" runat="server" Text="Go" onclick="GoButton_Click" />

then the page directive is as follows 那么页面指令如下

<%@ Page language="c#"  EnableEventValidation="false" Codebehind="AdminHotelEdit.aspx.cs" AutoEventWireup="false" Inherits="GTIAdmin.AdminHotelEdit" ValidateRequest="false"%>

and i have the button click event defined in code behind file as follows 我有在文件后面的代码中定义的按钮单击事件,如下所示

public void GoButton_Click(object sender, EventArgs e)
{
}

when i debug program is getting error stating that 当我调试程序得到错误说明

Error   146 'ASP.edit_aspx' does not contain a definition for 'GoButton_Click'
and no extension method 'GoButton_Click' accepting a first argument of type
'ASP.adminhoteledit_aspx' could be found (are you missing a using directive or an
assembly reference?)    

please suggest me if you have idea about the reason of this error. 如果您对这个错误的原因有所了解,请提出建议。

the code in edit.cs is as follows edit.cs中的代码如下

namespace GTIAdmin
{
    /// <summary>
    /// Summary description for AdminHotelEdit.
    /// </summary>

    public class AdminHotelEdit : GTIAdminPage
    {
        protected Button GoButton_Click;

        private void Page_Load(object sender, System.EventArgs e)
        {

        }

        public void GoButton_Click(object sender, EventArgs e)
        {

        }
    }
}

Show us the contents of 'Edit.aspx.cs' 向我们展示'Edit.aspx.cs'的内容

-- edit: -编辑:

The 'inherits' field is blank. “继承”字段为空白。 Set it to the name of the class in 'Edit.aspx.cs' and life should be good. 将其设置为“ Edit.aspx.cs”中类的名称,生活应该会很好。

-- edit again: -再次编辑:

Nope. 不。 It's because AutoEventWireup is false. 这是因为AutoEventWireup为false。

Change this... 改变这个...

    protected Button GoButton_Click;

...to this... ...对此...

    protected Button GoButton;

...to match the ID of the button in your ASPX and eliminate a name conflict with your event handler method. ...以匹配ASPX中按钮的ID,并消除与事件处理程序方法的名称冲突。

public void GoButton_Click(object sender, EventArgs e)

尝试这个..

protected void GoButton_Click(object sender, EventArgs e)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM