aspx页面传值常用几种方式
1 page1.aspx 2 protected void Button1_Click(object sender, EventArgs e) 3 { 4 Response.Redirect("page2.aspx?name=" + TextBox1.Text); 5 } 6 page2.aspx 7 if (Request.QueryString["name"] != null) 8 { 9 TextBox1.Text = Request.QueryString["name"]; 10 }
1 protected void Button1_Click(object sender, EventArgs e) 2 { 3 //Cookies由服务器端创建,但保存在客户端 4 HttpCookie cName = new HttpCookie("Name"); 5 cName.Value = TextBox1.Text; 6 Response.Cookies.Add(cName); 7 Response.Redirect("page2.aspx"); 8 } 9 10 protected void Page_Load(object sender, EventArgs e) 11 { 12 if (Request.Cookies["Name"] != null) 13 { 14 TextBox1.Text = Request.Cookies["Name"].Value; 15 } 16 }
1 protected void Button1_Click(object sender, EventArgs e) 2 { 3 Session["ses"] = TextBox1.Text; 4 Response.Redirect("page2.aspx"); 5 } 6 protected void Page_Load(object sender, EventArgs e) 7 { 8 if(Session["ses"]!=null) 9 { 10 TextBox1.Text = Session["ses"].ToString(); 11 } 12 }
1 protected void Button1_Click(object sender, EventArgs e) 2 { 3 Application["app"] = TextBox1.Text; 4 Response.Redirect("page2.aspx"); 5 } 6 protected void Page_Load(object sender, EventArgs e) 7 { 8 if (Application["app"] != null) 9 { 10 TextBox1.Text = Application["app"].ToString(); 11 } 12 }
1 public string Name { get { return this.TextBox1.Text.Trim().ToString(); } } 2 protected void Button1_Click(object sender, EventArgs e) 3 { 4 Server.Transfer("page2.aspx"); 5 } 6 7 --在page2.aspx页面引入:<%@ Reference Page="~/page1.aspx" %> 8 protected void Page_Load(object sender, EventArgs e) 9 { 10 page1 p = (page1)Context.Handler; 11 //TextBox1.Text = p.Name;这样也可以 12 TextBox1.Text = ((TextBox)p.FindControl("TextBox1")).Text; 13 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。