ASP.NET 页面之间传递参数方法

1、通过URL链接地址传递 
(1) send.aspx代码 

protected void Button1_Click(object sender, EventArgs e) 

Request.Redirect("Default2.aspx?username=honge"); 


(2) receive.aspx代码 

string username = Request.QueryString["username"];//这样可以得到参数值。 


2、POST方式传递 
(1) send.aspx代码 

<form id="form1" runat="server" action="receive.aspx" method=post> 
<div> 
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> 
<asp:TextBox ID="username" runat="server"></asp:TextBox> 
</div> 
</form> 


(2) receive.aspx代码 

string username = Ruquest.Form["receive"]; 


3、Session方式传递 
(1) send.aspx代码 

protected void Button1_Click(object sender, EventArgs e) 

Session["username"] = "honge"; 
Request.Redirect("Default2.aspx"); 


(2) receive.aspx代码 

string username = Session["username"];//这样可以得到参数值。 


4、Application方式传递 
(1) send.aspx代码 

protected void Button1_Click(object sender, EventArgs e) 

Application["username"] = "honge"; 
Request.Redirect("Default2.aspx"); 


(2) receive.aspx代码 

string username = Application["username"];这样可以得到参数值。 


5、使用Server.Transfer进行传递 
(1) send.aspx代码 

public string Name 

get { 
return "honge"; 


protected void Button1_Click(object sender, EventArgs e) 

Server.Transfer("Default2.aspx"); 


(2) receive.aspx代码 


send d = Context.Handler as send ; 
if (d != null) 

Response.Write(d.Name);//这样可以得到参数值。 
posted @ 2015-04-03 16:46  即兴随缘  阅读(188)  评论(0编辑  收藏  举报