asp.Net不同頁之間傳值

1, 發送頁:
     Application["sum"]=this.TextBox1.Text;
     Server.Transfer("WebForm2.aspx");   
    //用Server.Transfer不會轉變網頁地址欄,但網頁已經轉                                                                                    
   接收頁:
     this.TextBox1.Text=(string)Application["sum"];
Application實質上是整個虛擬目錄中所有文件的集合,如果想在整個應用範圍內使用某個變量值,Application對象將是最佳的選擇
2, 發送頁:
    private void button_click(object sender,System.EventArgs e)
{
   string url;
   url="webform2.aspx?name="+TextBox1.Text ;
   Response.Redirect(url);
}
  接收頁:
  private void Page_Load(object sender,System.EventArgs e)
{
    Label1.Text=Request.QueryString["name"];
}
 //Querystring是一種非常簡單的傳值方式,其缺點就是會把要傳送的值顯示在瀏覽器的地址欄中
3, 發送頁:
private void button_click(object sender,System.EventArgs e)
{
    Session["Name"]=TextBox1.Text;
    Response.Redirect("webform2.aspx");
}
  接收頁:
private void Page_Load(object sender,System.EventArgs e)
{
    Label1.Text=Session["Name"].ToString();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章