我是 .NET 新手,正在尝试基本功能。当我放置提交按钮时出现错误。请仔细检查代码,如果我使用的“提交”按钮语法错误,请告诉我。
代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>My First web page</title>
</head>
<body>
<form id="form1" runat="server" >
<div style="position:absolute">
First Name :<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br/>
Last Name :<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button OnClick="submit" Text="submit" runat="server" />
</div>
</form>
</body>
</html>
错误是:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'ASP.webform1_aspx' does not contain a definition for 'submit' and no extension method 'submit' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)
谢谢。
最佳答案
您必须向 OnClick 提供服务器端 OnClick 处理程序,并且提交可能未定义为处理程序。这个MSDN Button.OnClick documentation讲述 OnClick 事件处理程序如何与按钮关联。您还需要为您的按钮提供ID。
从按钮中删除 OnClick 属性。在 VS 设计器中打开表单双击 VS 设计器中的按钮,它将为您生成处理程序。您可以在How to: Create Event Handlers in ASP.NET Web Forms Pages中找到模式
生成事件处理程序后,您会得到类似的结果。
隐藏代码
void yourButtonId_Click(Object sender, EventArgs e)
{
}
HTML (aspx)
<asp:Button ID="yourButtonId" OnClick="yourButtonId_Click" Text="submit" runat="server" />
关于asp.net - ASP.net 中的提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35598147/