asp.net - ASP.net 中的提交按钮

标签 asp.net forms submit

我是 .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/

相关文章:

asp.net - Web 配置转换不适用于 Visual Studio Online、VS2013 和 Azure

html - 图例不适合(不同的分辨率)

html - 使用http获取html表单数据

submit - knockout.js 基本提交绑定(bind)问题

jQuery 提交解决方法

c# - 如何在 HTML head 中查找和删除 CSS 引用?

javascript - 如何使用 jQuery Autocomplete item click 重定向到另一个页面

c# - 在展开/折叠时禁用 TreeView 节点上的回发

javascript - 我可以使用提交按钮和JS提交表单吗?

jquery - 是否可以在 jQuery 中提交 multipart/form-data 而不刷新页面?