zoukankan      html  css  js  c++  java
  • 页面传参的几种方式

    页面之间传值的几种方法

    1.Get方式

       发送页代码:Response.Redirect("WebFormA2.aspx?name=" + TextBox1.Text);

       接收页代码:

                 this.TextBox1.Text = Request["name"];
                //this.TextBox1.Text=Request.Params["name"];
                //this.TextBox1.Text=Request.QueryString["name"];

    2.使用内存变量

        发送页代码:

               Session["name"] = this.TextBox1.Text;
                //Application["name"]=this.TextBox1.Text;

         接收页代码:

                this.TextBox1.Text = (string)Session["name"];
              //this.TextBox1.Text = (string)Application["name"];

    3.Post方式

         发送页代码:

           <form id="form1" runat="server" action="WebFormC2.aspx" method="post">
                     <input name="txtname" type="text" value="Andy"/>
                     <input type="submit" value="提交到WebFormC2.aspx"/>   
            </form>

           接收页代码:

               if (Request.Form["txtname"] != null)
                {
                    TextBox1.Text = Request.Form["txtname"];
                }

        注意:<form>中不能带runat="server".否则不起作用.

                <form>中的mothod="post"

    4.静态变量

             发送页代码:

                   //定义一个公共变量
                     public static string str = "";
                     protected void Button1_Click(object sender, EventArgs e)
                    {
                         str = this.TextBox1.Text;
                         Response.Redirect("WebFormD2.aspx");
                     }

               接收页代码:  this.TextBox1.Text = WebFormD1.str;

     5.Context.Handler获取控件

            发送页代码:

                  <asp:TextBox ID="TextBox1" Text="Andy" runat="server"></asp:TextBox>
                   <asp:Button ID="Button1" runat="server" Text="进入WebFormE2.aspx" OnClick="Button1_Click" />

                  //Button1_Click事件代码

                  Response.Redirect("WebFormE2.aspx");

             接收页面代码:

                   //获取post过来的页面对象
                if (Context.Handler is WebFormE1)
                {
                    //取得页面对象
                    WebFormE1 poster = (WebFormE1)Context.Handler;

                    //取得控件               
                    this.TextBox1.Text = ((TextBox)poster.FindControl("TextBox1")).Text;
                    //this.TextBox1.Text = poster.TextBox1.Text;
                }

    6.Context.Handler获取公共变量

            发送页代码:

                 //定义一个公共变量
                 public string strname = "Andy";
                 protected void Button1_Click(object sender, EventArgs e)
                {            
                     Response.Redirect("WebFormE2.aspx");           

                }

           接收页代码:

                //获取post过来的页面对象
                if (Context.Handler is WebFormF1)
                {
                    //取得页面对象
                    WebFormF1 poster = (WebFormF1)Context.Handler;
                    this.TextBox1.Text = poster.strname;
                }

    7.Context.items变量

         发送页代码:

                protected void Button1_Click(object sender, EventArgs e)
                {
                      Context.Items["name"] = TextBox1.Text;
                      Server.Transfer("WebFormG2.aspx");
                 }

           接收页代码:

                  //获取post过来的页面对象
                if (Context.Handler is WebFormG1)
                {
                    this.TextBox1.Text = Context.Items["name"].ToString();
                }

  • 相关阅读:
    强连通分量入度和出度
    Tarjan 强连通分量
    强连通是真的强~
    Yii2.0 RESTful API 基础配置教程
    微信小程序循环数组展示数据点击当前改变当前按钮状态
    初入博客园
    博客总目录
    当我们在谈论kmeans(4)
    当我们在谈论kmeans(5)
    当我们在谈论kmeans(3)
  • 原文地址:https://www.cnblogs.com/felix-/p/4319705.html
Copyright © 2011-2022 走看看