看起來好像你正在使用ASP.NET Web窗體(因爲你有一個實際的ASPX文件)。
如果是這種情況,ASP.NET會爲您處理相當多的事情,並且實際上會自行執行POST
,這可以讓您的代碼隱藏內容。
當表單張貼你可以考慮與實際指向一個特定的方法替換現有的submit
按鈕,在你的命中後臺代碼:
<asp:Button ID="AddPassword" Text="Add Password" ... OnClick="AddPassword_Click"><asp:Button>
的OnClick
事件將處理映射您的按鈕被點擊一個事件在aspx.cs
文件看起來像:
protected void AddPassword_Click(object sender, EventArgs e)
{
// This code will be executed when your AddPassword Button is clicked
}
如果您有相關的ASP.NET代碼替換整個代碼,它看起來像以下部分(S):
YourPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="YourPage.aspx.cs" Inherits="YourProject.YourPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Password Checking</title>
</head>
<body>
<!-- This will post back to your YourPage.aspx.cs code-behind -->
<form id="form1" runat="server" name="edit_password_form">
<div id="edit_password_popup">
<table width="390" align="center" padding="10">
<tr>
<td><span class="error_field">*</span>Password:<br />
<!-- Replaced <input> elements with matching <asp:TextBox> controls -->
<asp:TextBox ID="Password1" runat="server" TextMode="Password" size="19" maxlength="30" autocapitalize="off" autocorrect="off" autocomplete="off"></asp:TextBox>
</td>
<td><span class="error_field">*</span>Confirm Password:<br>
<asp:TextBox ID="Password2" runat="server" TextMode="Password" size="19" maxlength="30" autocapitalize="off" autocorrect="off" autocomplete="off"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<!-- Updated submit button to proper <asp:Button> -->
<asp:Button ID="AddPassword" runat="server" Text="Add Password" OnClick="AddPassword_Click" alt="Add Password" border="0"><asp:Button>
</td>
<td>
<input type="reset" value="No Thanks" id="no_thanks" alt="No Thanks" border="0" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
YourPage.aspx.cs
public partial class YourPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// This will get called when your form is submitted
protected void AddPassword_Click(object sender, EventArgs e)
{
// When your page is posted back, compare your passwords
if(String.Equals(Password1.Text,Password2.Text))
{
// Your passwords are equal, do something here
}
else
{
// They aren't equal, do something else
}
}
}
首先,將表單元素中的動作更改爲實際的後端端點。然後在該端點的代碼隱藏中,您可以處理髮布的數據。 – ohiodoug
那麼行動路徑是aspx.cs文件? – Learn12
不,操作路徑是.aspx文件。也就是說,如果你沒有做任何URL重寫。 – ohiodoug