一:用過的:
(1)通過URL連結地址傳遞 (加?..多個參數時加¶2=value中間不能有空格如href="receive.aspx?username=honge&pwd=123")
send.aspx:
//或者頁面<a href="receive.aspx?username=honge"></a>
protected void Button1_Click(object sender, EventArgs e)
{ Request.Redirect("receive.aspx?username=honge"); }
receive.aspx:
string username = Request.QueryString["username"];這樣可以得到參數值。
ps1:傳遞的參數預設都是string類型,所以不必加引號,也不必類型轉換後傳遞,在接收方為string類型.<漢字除外>
ps2:當傳遞多個參數時,用&隔開,注意不能有空格
ps3:當傳遞漢字時,常常先進行類型轉換, System.Web.HttpUtility.UrlEncode("你好!");
(2) 通過session
send.aspx:
protected void Button1_Click(object sender, EventArgs e)
{ Session["username"] = "honge"; Request.Redirect("Default2.aspx"); }
receive.aspx:
string username = Session["username"]; 這樣可以得到參數值。
(3)通過cook:
send:
Request.Cookies.Add(new HttpCookie("cookie_stop2_class","education"));
receive:
HttpCookie myCook = Request.Cookies["cookie_stop2_class"];
if(myCook!= null){
string str =myCook.Value; //str = education;
}
(4)通過Application
send.aspx:
protected void Button1_Click(object sender, EventArgs e)
{ Application["username"] = "honge"; Request.Redirect("Default2.aspx"); }
receive.aspx: string username = Application["username"];這樣可以得到參數值。
(5)通過Server.Transfer
send.aspx:
public string Name { get { return "honge"; } }
protected void Button1_Click(object sender, EventArgs e)
{ Server.Transfer("Default2.aspx"); }
receive.aspx:
send d = Context.Handler as send ;
if (d != null) { Response.Write(d.Name);}