在之前假设第一个页面为send.aspx,第二个页面为receive.aspx
1、通过URL链接地址传递
(1) send.asp代码
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.asp代码
<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.asp代码
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.asp代码
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.asp代码
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)//这样可以得到参数值。
}
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
{
//用HiddenField保存传进来的值
HiddenField1.Value = this.Request.QueryString["EditionID"]
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//第一个按钮:
HiddenField1.Value = "cn"//或者="en"自己去改
this.Response.Redirect("xxx.aspx?ppp1=dsfsd&EditionID=" + HiddenField1.Value)
}
protected void Button2_Click(object sender, EventArgs e)
{
//第二个按钮:
HiddenField1.Value = "en"//或者="en"自己去改
this.Response.Redirect("xxx.aspx?ppp1=dsfsd&EditionID=" + HiddenField1.Value)
}
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)