標籤: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 }