我搜索互聯網上,但沒有發現任何最好的解決方法的另一頁上的崗位價值的最佳方法,我發現了一個辦法,在這裏你需要像什麼是檢索在ASP.net 4.0
<input type='text'> ... etc etc
編寫HTML標籤
和檢索作爲
Request.Form["name of input text field"];
W3Schools -ASP Forms and User Input
存在什麼更好的方法來檢索崗位價值的另一個頁面上的價值?
我搜索互聯網上,但沒有發現任何最好的解決方法的另一頁上的崗位價值的最佳方法,我發現了一個辦法,在這裏你需要像什麼是檢索在ASP.net 4.0
<input type='text'> ... etc etc
編寫HTML標籤
和檢索作爲
Request.Form["name of input text field"];
W3Schools -ASP Forms and User Input
存在什麼更好的方法來檢索崗位價值的另一個頁面上的價值?
ASP.NET WebForms支持跨頁面發佈。請閱讀http://msdn.microsoft.com/en-us/library/ms178139.aspx和http://msdn.microsoft.com/en-us/library/ms178140.aspx瞭解更多信息。
實施例:
WebForm1.aspx的: 注意在asp:按鈕具有其PostBackUrl屬性集。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFormApplication.WebForm1" EnableViewStateMac="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" >
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="WebForm2.aspx" />
</div>
</form>
</body>
</html>
WebForm2.aspx: 請注意,我在這裏添加了PreviousPageType指令。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebFormApplication.WebForm2" %>
<%@ PreviousPageType VirtualPath="WebForm1.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is page 2
<asp:Label Text="n/a" runat="server" ID="Label1" ></asp:Label>
</div>
</form>
</body>
</html>
WebForm2.aspx.cs:(代碼隱藏)
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(PreviousPage.IsCrossPagePostBack)
{
var tb = PreviousPage.FindControl("TextBox1") as TextBox;
Label1.Text = tb.Text;
}
}
}
爲什麼在使用PreviousPage的時候可以簡單地使用Request.Form [「TextBox1」],訪問PreviousPage會爲前一頁執行整個頁面的生命週期 – 2012-01-05 20:18:26
謝謝這個幫助我很多 – 2012-01-06 11:30:04
@AntonioBakula:AFAIK你不會運行上一頁的生命週期與PreviousPage。 – 2012-01-08 12:28:32
您所提供的例子是ASP頁有用的,但我建議使用QueryString集合在asp.net
這裏web表單之間傳遞參數是如何使用它的一個例子:
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
string v = Request.QueryString["Param1"];
if (v != null)
{
Response.Write("param is ");
Response.Write(v);
}
}
}
您可以使用Response.Redirect連接URL:
string _url = string.Format("../WebFormA.aspx?Param1={0}&Param2={1}", _param1, _param2);
Response.Redirect(_url);
此致。
我沒有看到任何真正的優勢從使用QueryString(GET )over Form(POST) – Rafael 2012-01-05 19:16:21
澄清 「最佳」 是指給你。性能?打字?簡潔?強大的? – RedFilter 2012-01-05 18:45:20
我認爲你的意思是獲取請求的發佈價值(當然,將其作爲最初的一個頁面)。如果是這樣,是的,就是這樣。你面臨的問題是什麼?這很簡單。 – ivowiblo 2012-01-05 18:46:30
花了我一會兒才知道你在問什麼,但你查詢字符串是我用過的:) – 2012-01-05 19:16:22