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"]
  • 相关阅读:
    php7安装Memcached扩展
    php7安装
    结束进程
    openssl 编译
    boost 编译
    php 与 c++ openssl 加密通信
    iptables 端口转发
    获取进程及父进程的两种方式
    windows 下获取父进程pid
    CentOS 64位系统 yum安装32位软件包的方法
  • 原文地址:https://www.cnblogs.com/ibgo/p/3329362.html
Copyright © 2011-2022 走看看