ASP.NET頁面之間傳遞值(1):QueryString

來源:互聯網
上載者:User

標籤:style   blog   color   使用   art   io   

QueryString是一種非常簡單的傳值方式,他可以將傳送的值顯示在瀏覽器的地址欄中。如果是傳遞一個或多個安全性要求不高或是結構簡單的數值時,可以使用這個方法。但是對於傳遞數組或對象的話,就不能用這個方法了。

  這種方法的優點:1.使用簡單,對於安全性要求不高時傳遞數字或是文本值非常有效。
  這種方法的缺點:1.缺乏安全性,由於它的值暴露在瀏覽器的URL地址中的。
          2.不能傳遞對象。

  使用方法:1.在源頁面的代碼中用需要傳遞的名稱和值構造URL地址。
       2.在源頁面的代碼用Response.Redirect(URL);重新導向到上面的URL地址中。
       3.在目的頁面的代碼使用Request.QueryString["name"];取出URL地址中傳遞的值。

這是indextest.aspx後台頁面:

 1 using System; 2 using System.Collections.Generic; 3 using System.Web; 4 using System.Web.UI; 5 using System.Web.UI.WebControls; 6  7 public partial class JajaWeixinQianduanWeb_WoYaoDingCan_indextest : System.Web.UI.Page 8 { 9     protected void Page_Load(object sender, EventArgs e)10     {11 12     }13 14     protected void btn_chuanzhi_Click(object sender, EventArgs e)15     {16         string s_url;17         s_url = "indextestlist.aspx?name=" + this.txt_chuanzhi.Value;18         Response.Redirect(s_url); 19     }20 }

這是indextestlist.aspx後台頁面:

 1 using System; 2 using System.Collections.Generic; 3 using System.Web; 4 using System.Web.UI; 5 using System.Web.UI.WebControls; 6  7 public partial class JajaWeixinQianduanWeb_WoYaoDingCan_indextestlist : System.Web.UI.Page 8 { 9     protected void Page_Load(object sender, EventArgs e)10     {11         this.lab_zhi.Text = Request.QueryString["name"]; 12     }13 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.