我有一個C#aspx的形式,我需要輸入它的數據到SQL數據庫,然後返回一個響應說成功與否。我不知道如何獲取從Default.aspx頁面發送的表單數據。我的基本代碼結構如下:C#ASPX - 表單提交查詢
Default.aspx的
<form runat="server" name="aForm" action="Results.aspx" method="post" onsubmit="ValidateForm()">
<input name="firstname" type="text" />
<input name="surname" type="text" />
<input type="submit" value="Submit" />
</form>
Results.aspx.cs
public partial class AwardsForm : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!this.IsPostBack){
Response.Redirect("Default.aspx");
} else (this.IsPostBack) {
writeResults(FormSubmit());
}
protected boolean FormSubmit() {
// get form data and insert it into SQL
// return true/false based on success
}
protected void writeResults(boolean results) {
if (results == true) {
Response.Write ("Success");
} else {
Response.Write ("Failed");
}
}
}
非常感謝,看起來不錯。有關這臺機器關鍵業務的任何想法?這是本地表格,不會在網上使用。 我曾嘗試不採取以下措施:http://sharemypoint.wordpress.com/2009/04/15/machinekey-in-webconfig/。 – 2011-12-19 22:36:17
不知道機器的關鍵東西@Bonjour - 對不起 – 2011-12-20 00:07:21
沒問題,我用它在頁面上使用了黑客工作。謝謝你的回覆,非常感謝。 – 2011-12-20 01:11:31