ASP.Net中传递参数的常见方法
标签: |
第一种ASP.Net参数传递方法:通过URL链接地址传递
send.aspx:protected void Button1_Click(object sender, EventArgs e){ Request.Redirect("Default2.aspx?username=honge");}receive.aspx:string username = Request.QueryString["username"];这样可以得到参数值。第二种ASP.Net参数传递方法: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"];第三种ASP.Net参数传递方法:send.aspx:
protected void Button1_Click(object sender, EventArgs e) { Session["username"] = "honge";Request.Redirect("Default2.aspx");
}receive.aspx:string username = Session["username"];这样可以得到参数值。
第四种ASP.Net参数传递方法:send.aspx:
protected void Button1_Click(object sender, EventArgs e) { Application["username"] = "honge"; Request.Redirect("Default2.aspx"); }receive.aspx:string username = Application["username"];这样可以得到参数值。第五种ASP.Net参数传递方法: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);这样可以得到参数值。 }
原文地址: