2011-12-08 56 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