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();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章