2011-12-08 101 views
-2

當我單擊提交按鈕時,應該將這些值傳遞給另一個頁面,如何獲取名稱和年齡的文本字段?我該怎麼做? NAME AGE如何獲取文本值

SUBMIT

protected void Page_Load(object sender, EventArgs e) 

{ 

     { 

      litText.Text = Request.Form["tbName"] + ": " + Request.Form["tbAge"]; 
     } 
    } 

    public Default3() 
    { 
     Load += Page_Load; 
    } 
} 
+1

你究竟在做什麼?當我點擊提交按鈕時,顯示你的代碼 – Bas

+0

輸入的值應該顯示在另一個網頁 –

回答

4

在.aspx文件:

<asp:TextBox id="txbAge" runat="server"></asp:TextBox> 
<asp:TextBox id="txbName" runat="server"></asp:TextBox> 
<asp:Button id="btnSubmit" runat="server" onclick="btnSubmit_Click" /> 

在aspx.cs文件:

protected void btnSubmit_Click(object sender, EventArgs e) 
{ 
    string age = txbAge.Text; 
    string name = txbName.Text; 
    string url = string.Format("~/anotherPage.aspx?age={0}&name={1}", age, name); 
    Response.Redirect(url); 
} 

在第二.aspx文件:

<aspx:Label id="lblAge" runat="server"></aspx:Label> 
<aspx:Label id="lblName" runat="server"></aspx:Label> 

在第二.aspx.cs文件:

protected void Page_Load(object sender, EventArgs e) 
{ 
    string age = string.Empty; 
    string name = string.Empty; 

    if(!String.IsNullOrEmpty(Request.QueryString["age"])) 
    age = Request.QueryString["age"]; 
    if(!String.IsNullOrEmpty(Request.QueryString["name "])) 
    age = Request.QueryString["name "]; 

    lblAge.Text = age; 
    lblName.Text = name; 

} 

這是路怎麼走在查詢字符串另一頁上這些值。

Mariusz

+2

,然後在另一頁上,你可以使用Request.QueryString [「age」]和Request.QueryString [ 「name」]' – ThePower

+0

對,我忘了寫這個。 – Mariusz

+0

將其添加到您的答案。使它成爲完整的文章:-) – ThePower