原文:
第一种方法:
通过URL链接地址传递send.aspx: protected void Button1_Click(object sender, EventArgs e) { Request.Redirect("Default2.aspx?username=honge"); }receive.aspx:string username = Request.QueryString["username"];这样可以得到参数值。第二种方法:
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>receive.aspxstring username = Ruquest.Form["receive"];第三种方法:
send.aspx: protected void Button1_Click(object sender, EventArgs e) { Session["username"] = "honge"; Request.Redirect("Default2.aspx"); }receive.aspx:string username = Session["username"];这样可以得到参数值。第四种方法:
send.aspx: protected void Button1_Click(object sender, EventArgs e) { Application["username"] = "honge"; Request.Redirect("Default2.aspx"); }receive.aspx:string username = Application["username"];这样可以得到参数值。第五种方法:
send.aspx: public string Name { get { return "honge"; } } protected void Button1_Click(object sender, EventArgs e) { Server.Transfer("Default2.aspx"); }receive.aspx: send d = Context.Handler as send ; if (d != null) { Response.Write(d.Name);这样可以得到参数值。 }如果在asp.net 2.0中还可以这样用:
PreviousPage d = Context.Handler as PreviousPage ;
if (d != null) { Response.Write(d.Name);这样可以得到参数值。 }也可以这样用:send.aspx:<asp:Button ID="btnSubmit" runat="server" PostBackUrl="~/reveive.aspx" Text="Submit" />receive.aspx:<%@ PreviousPageType VirtualPath="~/Default.aspx" %>string name = PreviousPage.Name;这样可以得到参数值。如果你的页面中用到了MasterPage的话 Server.Transfer 传递的 PreviousPage就无效了,不知道这是什么原因.所以在用到MasterPage的话,最好用Session或是Context.Items["username"]来实现.