頁面中用Context.Handler傳遞
阿新 • • 發佈:2017-05-05
傳遞 什麽 今天 rem 命名空間 變量 hand emp text 最近被WCF弄得身心疲憊。今天抽空看了一下頁面傳值的一些技巧。傳統的cookie session 什麽的就不介紹了
今天介紹Context的用法
首先要應用using System.Runtime.Remoting.Contexts;命名空間
public static string strname = "";
//靜態變量傳遞
strname = "wtyTest";
Server.Transfer("WebFormD2.aspx");
//接收頁面
string request = string.Empty;
request = WebFormD1.strname; //Context.Handler獲取控件 if (Context.Handler is WebFormE1)
{
//獲得頁面對象
WebFormE1 poster = (WebFormE1)Context.Handler;
//取得控件
TextBox.Text =(TextBox)poster.FindControl("TextBox1")).Text;
} //Context.Handler獲取公共變量 //發送頁面代碼
public static string strname = "";
strname = "wtyTest";
Server.Transfer("WebFormD2.aspx");
//接收頁面代碼
if (Context.Handler is WebFormE1)
{
//獲得頁面對象
WebFormE1 poster = (WebFormE1)Context.Handler;
TextBox.Text =poster.strname;
} //Context.items變量 //發送頁面代碼
Context.Items["name"]="wtytest";
Server.Transfer("WebFormD2.aspx");
//接收頁面代碼
if (Context.Handler is WebFormE1)
{
//
TextBox.Text =Context.Items["name"].ToString();
}
strname = "wtyTest";
Server.Transfer("WebFormD2.aspx");
//接收頁面
string request = string.Empty;
request = WebFormD1.strname; //Context.Handler獲取控件 if (Context.Handler is WebFormE1)
{
//獲得頁面對象
WebFormE1 poster = (WebFormE1)Context.Handler;
//取得控件
TextBox.Text =(TextBox)poster.FindControl("TextBox1")).Text;
} //Context.Handler獲取公共變量 //發送頁面代碼
public static string strname = "";
strname = "wtyTest";
Server.Transfer("WebFormD2.aspx");
//接收頁面代碼
if (Context.Handler is WebFormE1)
{
//獲得頁面對象
WebFormE1 poster = (WebFormE1)Context.Handler;
TextBox.Text =poster.strname;
} //Context.items變量 //發送頁面代碼
Context.Items["name"]="wtytest";
Server.Transfer("WebFormD2.aspx");
//接收頁面代碼
if (Context.Handler is WebFormE1)
{
//
TextBox.Text =Context.Items["name"].ToString();
}
頁面中用Context.Handler傳遞