0
說我創建一個靜態.html頁面。接下來,我用一堆輸入框構建一個表單。然後我決定將所有表單數據發佈到另一個頁面,將其稱爲process-form-data.aspx。我的問題是,自從我將表單數據發佈到.aspx頁面後,如何在屏幕背後的代碼中使用C#來獲取所有數據?收集表格數據從任何頁面發佈
我嘗試以下第一:
NameValueCollection nvc = Request.Form;
string valTextBox1;
if (!string.IsNullOrEmpty(nvc["txtBox1"]))
{
valTextBox1 = nvc["txtBox1"];
Response.Write(valTextBox1);
}
然後我想:
valTextBox1 = Request.Form["txtBox1"].ToString();
Response.Write(valTextBox1);
但無論方法似乎工作。如果我使用.apsx頁面上的runat =「server」屬性提交表單,我只能得到這兩種方法的工作方式。
我想避免通過URL傳遞變量。
感謝您的任何幫助。
'txtBox1'是您發佈的HTML輸入字段的名稱? – Brandon 2012-03-20 20:29:06
如果您不想使用GET,請使用POST。 – Chriseyre2000 2012-03-20 20:29:13
@Brandon是的,name屬性被設置爲name =「txtBox1」。 – 2012-03-20 20:32:49