• 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"]
  • 相关阅读:
    BZOJ BLO 1123 (割点)【双连通】
    P4291 [HAOI2008]排名系统
    P3165 [CQOI2014]排序机械臂
    P3224 [HNOI2012]永无乡
    P1169 [ZJOI2007]棋盘制作
    P2303 [SDOi2012]Longge的问题
    P2216 [HAOI2007]理想的正方形
    P2473 [SCOI2008]奖励关
    P2617 Dynamic Rankings
    P2518 [HAOI2010]计数
  • 原文地址:https://www.cnblogs.com/ibgo/p/3329362.html
Copyright © 2020-2023  润新知