通过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.aspx
string 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);这样可以得到参数值。
我用最后的方法就出错!