• 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);//这样可以得到参数值。 
  • 相关阅读:
    代理模式第一篇
    命令模式第二篇
    windows service 定时
    postman之asp.net webapi
    qq第三方登录
    core2.1下的identity 汉化
    asp.net core2.0里的Nlog
    Unable to create an object of type 'ApplicationDbContext'.
    identity使用mysql
    二进制位运算解决状态值
  • 原文地址:https://www.cnblogs.com/jixingsuiyuan/p/4390480.html
Copyright © 2020-2023  润新知