我是.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?)谢谢。
发布于 2016-02-24 17:31:03
您必须向OnClick提供服务器端提交处理程序,并且可能没有将OnClick定义为处理程序。此MSDN Button.OnClick documentation告知如何将OnClick事件处理程序与按钮连接在一起。您还需要为按钮提供ID。
从按钮中删除OnClick属性。在VS designer中打开窗体,双击VS designer中的按钮,它将为您生成处理程序。您可以在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" />发布于 2016-02-24 17:32:55
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Your name is " & txt1.Text
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>https://stackoverflow.com/questions/35598147
复制相似问题