六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

ASP.NET中使用Server.Transfer()方法在頁間傳值

[摘要]ASP.NET Server.Transfer()是在兩個頁面之間進行傳值的好方法,從A頁面Transfer到B頁面時,就可以在B頁面通過Context.Handler獲得A頁面的一個類的實例,從而在B調用A的各個成員對象。下面的示例建立了WebForm1和WebForm2,通過Server.Tr...
ASP.NET Server.Transfer()是在兩個頁面之間進行傳值的好方法,從A頁面Transfer到B頁面時,就可以在B頁面通過Context.Handler獲得A頁面的一個類的實例,從而在B調用A的各個成員對象。

下面的示例建立了WebForm1和WebForm2,通過Server.Transfer()方法演示在WebForm2中讀取WebForm1的文本框、讀取屬性、通過Context傳值、調用WebForm1的方法等:

WebForm1上放置一個TextBox1和一個Button1,程序如下:

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
Context.Items.Add("Context","Context from Form1");
}
public string Time
{
get{return DateTime.Now.ToString();}
}
public string TestFun()
{
return "Function of WebForm1 Called";
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer("WebForm2.aspx", true);
}


在WebForm2上放置一個Literal1控件,程序如下:

public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal Literal1;

private void Page_Load(object sender, System.EventArgs e)
{
string strTxt="";
WebForm1 oForm=(WebForm1)this.Context.Handler;
strTxt+="Value of Textbox:"+Request.Form["TextBox1"] +"<br>";
strTxt+="Time Property:"+oForm.Time +"<br>";
strTxt+="Context String:"+Context.Items["Context"].ToString() +"<br>";
strTxt+=oForm.TestFun() +"<br>";
Literal1.Text =strTxt;
}

#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}

補充說明,就是Transfer方法的第二個參數指示是否保留頁面的Form和QuerryString的值,你可以試著把它設為False,則在WebForm2中將讀不到TextBox1的值。



主站蜘蛛池模板: 亚洲天天综合 | 亚洲国产中文在线 | 天天操天天干天天干 | 在线免费观看亚洲视频 | 欧美性开放视频 | 亚洲欧美综合一区 | 天天操天天射天天色 | 日本午夜三级 | 欧美无遮挡一区二区三区 | 伊人影院在线播放 | 手机在线三级 | 日本中出 | 日韩黄色在线观看 | 青春草在线视频免费观看 | 欲色天天| 亚洲精品另类 | 日韩欧美在线视频 | 青青青视频在线播放视频 | 亚洲国产青草 | 网站在线观看mv视频 | 做a的视频免费 | 欧美小视频在线观看 | 外国一级黄色 | 天堂日本岛a| 天天干夜夜爽天天操夜夜爽视频 | 一本一道波多野结衣一区二区 | 日本女人在线观看 | 亚洲福利秒拍一区二区 | 亚洲人网 | 五月六月婷婷 | 香蕉狠狠干 | 亚洲综合小说网 | 日韩一区二区三区视频在线观看 | 中文字幕第一页在线 | 欧美一区日韩精品 | 天天草天天草 | 日韩怡红院 | 在线播放精品视频 | 日韩a级片 | 在线综合网 | 宅男午夜视频在线观看 |