ASPX表单在提交时没有调用代码隐藏

本文关键字:调用 代码 隐藏 表单 提交 ASPX | 更新日期: 2023-09-27 18:10:07

我面对一个相当奇怪的行为,我无法解释自己。在我的一个ASP.net页面上有以下表单:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Codebehind.aspx.cs" Inherits="Myclass.Test" %>
<form name="application" id="application" method="post">
<asp:Table runat="server" width="840" border="0" align="center" cellspacing="0" cellpadding="0" id="tbl_test">
...
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center" style="padding-top:10px">
<asp:Button onClick="Click" ID="btn" runat="server" Text="Submit!" Height="30" Width="150" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>

在aspx.cs程序集中,我有一个受保护的函数"点击",一旦用户单击表单中的按钮,应该被触发。然而,事实并非如此。什么也没发生,我按下按钮,代码中的函数永远不会做它该做的事。

我在这里错过了什么?

ASPX表单在提交时没有调用代码隐藏

您需要在表单上添加runat="server"属性

您是否使用带有验证的表单?如果是,请使用

<asp:Button ID="btn" runat="server" onClick="Click" Text="Submit" CausesValidation="false" />