我正在尝试在 Visual Studio asp.net 上构建一个程序,但每当我尝试单击带有 OnClick 事件的按钮时,我都会收到以下错误:
"CS1061: 'ASP.test_aspx' 不包含 'buttonClick' 的定义,并且找不到接受类型为 'ASP.test_aspx' 的第一个参数的扩展方法 'buttonClick'(您是否缺少 using 指令或程序集参考?)"
这是我的 HTML 供参考:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="MRAApplication.test" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="服务器"><标题></标题></头><身体><form id="form1" runat="server"><asp:Button id="b1" Text="Submit" runat="server" OnClick="buttonClick"/><asp:TextBox id="txt1" runat="server"/></div></表格></身体></html>这是我的代码:
使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Web;使用 System.Web.UI;使用 System.Web.UI.WebControls;命名空间 MRAApplication{公共部分类测试:System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}void buttonClick(对象发送者,EventArgs e){txt1.Text = "文本";}}}
请保持解释尽可能简单,因为我是编码新手.感谢您的任何帮助.:)
解决方案 您需要将您的事件处理程序声明为受保护:
protected void buttonClick(Object sender, EventArgs e){txt1.Text = "文本";}
标记本质上是一个继承自后面代码的类.为了使成员可以访问,他们需要受到保护或公开.
I am attempting to build a program on visual studio asp.net but whenever I try to click a button with an OnClick event I get the following error:
"CS1061: 'ASP.test_aspx' does not contain a definition for 'buttonClick' and no extension method 'buttonClick' accepting a first argument of type 'ASP.test_aspx' could be found (are you missing a using directive or an assembly reference?)"
Here is my HTML for reference:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="MRAApplication.test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button id="b1" Text="Submit" runat="server" OnClick="buttonClick" />
<asp:TextBox id="txt1" runat="server" />
</div>
</form>
</body>
</html>
and here is my code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MRAApplication
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void buttonClick(Object sender, EventArgs e)
{
txt1.Text = "Text";
}
}
}
Please keep explanations as simple as possible as I am new to coding. Thank you for any and all help. :)
解决方案 You need to declare your event handler as protected:
protected void buttonClick(Object sender, EventArgs e)
{
txt1.Text = "Text";
}
The markup is essentially a class that inherits from the code behind. In order for members to be accessible, they need to be protected or public.
这篇关于Asp.Net 不包含 buttonClick 的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
车牌检测有哪些好的算法?What are good algorithms for vehicle license plate detection?(车牌检测有哪些好的算法?)
Unity中图像的onClick事件onClick event for Image in Unity(Unity中图像的onClick事件)
运行总 C#Running Total C#(运行总 C#)
单击带有 JAvascript.ASP.NET C# 的超链接时删除目录Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(单击带有 JAvascript.ASP.NET C# 的超链接时删除目录)
asp.net listview 在单击时突出显示行asp.net listview highlight row on click(asp.net listview 在单击时突出显示行)
从函数调用按钮 OnClickCalling A Button OnClick from a function(从函数调用按钮 OnClick)