C# 不包含asp.net页面中按钮单击事件的定义错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1287025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does not contain definition error for Button click event in asp.net page
提问by subha
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)
{
}
}
}
回答by Noon Silk
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 是假的。
回答by dahlbyk
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,并消除与事件处理程序方法的名称冲突。
回答by user3661035
public void GoButton_Click(object sender, EventArgs e)
try this..
尝试这个..
protected void GoButton_Click(object sender, EventArgs e)