zoukankan      html  css  js  c++  java
  • ASP.NET 不同页面之间传值

    不同页面之间如何传值?我们假设A和B两个页面,A是传递,B是接收。

    下面学习4种方式:

    1. 通过URL链接地址传递
    2. POST方式传递
    3. Session方式传递
    4. Application方式传递

    1. 通过URL链接地址传递

    A:
    protected void Button1_Click(object sender, EventArgs e)
    {
      Request.Redirect("Default2.aspx?username=honge");
    }
    
    B:
    string username = Request.QueryString["username"];

    2. POST方式传递

    A:
    <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>
    
    B:
    string username = Ruquest.Form["receive"];

    3. Session方式传递

    A:
    protected void Button1_Click(object sender, EventArgs e)
    {
      Session["username"] = "传递";
      Request.Redirect("Default2.aspx");
    }
    
    B:
    string username = Session["username"];

    4. Application方式传递

    A:
    protected void Button1_Click(object sender, EventArgs e)
    {
      Application["username"] = "传递";
      Request.Redirect("Default2.aspx");
    }
    
    B:
    string username = Application["username"]
  • 相关阅读:
    JSON.parse()和JSON.stringify()
    php结合layui实现前台加后台操作
    微信拨打电话功能
    视觉差效果
    前端开发面试题
    字符串分割--java中String.split()用法
    vue.js实现购物车功能
    localStorage使用总结
    canvas 实现赛车小游戏
    canvas 实现飞碟射击游戏
  • 原文地址:https://www.cnblogs.com/ibgo/p/3329362.html
Copyright © 2011-2022 走看看