ASPX表单在提交时不调用codebehind

时间:2013-04-19 17:36:13

标签: c# asp.net html

我面临着一种奇怪的行为,我无法解释自己。我在我的一个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程序集中,我有一个受保护的函数“Click”,一旦用户单击表单中的按钮就会被触发。但事实并非如此。没有任何反应,我按下按钮,我的代码隐藏中的功能永远不会发挥作用。

我在这里缺少什么?

2 个答案:

答案 0 :(得分:4)

您需要在表单

上添加runat="server"属性

答案 1 :(得分:0)

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

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