JaG*_*aGo 8 c# asp.net onclick
我试图在visual studio asp.net上构建一个程序,但每当我尝试单击一个带有OnClick事件的按钮时,我都会收到以下错误:
"CS1061:'ASP.test_aspx'不包含'buttonClick'的定义,并且没有扩展方法'buttonClick'接受类型'ASP.test_aspx'的第一个参数可以找到(你是否缺少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="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>
Run Code Online (Sandbox Code Playgroud)
这是我的代码背后:
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";
}
}
}
Run Code Online (Sandbox Code Playgroud)
因为我不熟悉编码,请尽可能简单地解释.感谢您的帮助.:)
Ben*_*son 14
您需要将事件处理程序声明为protected:
protected void buttonClick(Object sender, EventArgs e)
{
txt1.Text = "Text";
}
Run Code Online (Sandbox Code Playgroud)
标记本质上是一个继承自后面代码的类.为了使成员可以访问,他们需要受到保护或公开.
| 归档时间: |
|
| 查看次数: |
12078 次 |
| 最近记录: |