發送資料到其他頁面的方法:(在url上看不到所傳送的參數)

來源:互聯網
上載者:User
 

方法一:

    GET方法是將傳遞的資料追加至uRL中。uRL地址長度是有限制的,因此使用GET

方法所能傳遞的資料也是有限。一般地,GET方法能夠傳遞256位元組的資料。在多數情況

下,使用GET方法傳遞的資料長度是遠遠不夠的,這時便需要使用HTTP的另外—種請求

方式PosT,PosT方法可傳遞的資料的最大值為2MB。

    PosT請求必須由ForM發出(使用Sock方法直接寫入HTTP前序的方法除外)。如:

<form  action="Getinfo1.aspx"  method="post">

您的人名:<inPut  typee="text”  name="nickname"><br>

<inPut  type=”submit“  value="發送">

<form>

使用POST請求時,<form>標籤中的method屬性值設定為POST。

A5P.net使用Request.Form方法接收POST方法傳遞的資料。

Request.Form[”variable“]

發送頁面的部分代碼:

<form id="FormPost_1" action="rec1FormPost_2.aspx" method="post">

            <FONT face="黑體">Name : <INPUT name="text1" type="text" value="Jerry"> <INPUT type="submit" value="提交"></FONT>

        </form>

注意:action屬性指明用reclFormPost_2.aspx為接收頁面。

接收頁面的部分代碼:

private void Page_Load(object sender, System.EventArgs e)

        {

            Response.Write("Hello "+Request.Form["text1"]);

        }

方法二:

發送頁面的部分代碼:

protected System.Web.UI.WebControls.TextBox TextBox1;

        public  System.Web.UI.WebControls.TextBox TextBox2;

        protected System.Web.UI.WebControls.Button Button1;

private void Button1_Click(object sender, System.EventArgs e)

        {

                Server.Transfer("rec3FormPost_4.aspx");

        }

接收頁面的部分代碼:

private void Page_Load(object sender, System.EventArgs e)

        {

            //擷取post過來的頁面對象

            if (Context.Handler is FormPost_3)

            {

                //取得頁面對象

                FormPost_3 poster=(FormPost_3)Context.Handler;

                //取得控制項

                Response.Write("Hello " + ((TextBox)poster.FindControl("TextBox1")).Text + "<p>");

                Response.Write("Hello " + poster.TextBox2.Text );

            }

        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.