人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開發(fā)教程 > 詳細頁面

ASP.NET中運用Server.Transfer()辦法在頁間傳值

ASP.NET中運用Server.Transfer()辦法在頁間傳值

更新時間:2022-10-12 文章作者:未知 信息來源:網(wǎng)絡 閱讀次數(shù):

ASP.NET Server.Transfer()是在兩個頁面之間進行傳值的好方法,從A頁面Transfer到B頁面時,就可以在B頁面通過Context.Handler獲得A頁面的一個類的實例,從而在B調(diào)用A的各個成員對象。

下面的示例建立了WebForm1和WebForm2,通過Server.Transfer()方法演示在WebForm2中讀取WebForm1的文本框、讀取屬性、通過Context傳值、調(diào)用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方法的第二個參數(shù)指示是否保留頁面的Form和QuerryString的值,你可以試著把它設為False,則在WebForm2中將讀不到TextBox1的值。

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 南乐县| 成武县| 仪征市| 社旗县| 霸州市| 临邑县| 石城县| 武城县| 兰溪市| 克山县| 西充县| 南溪县| 凤城市| 宜良县| 固始县| 宜君县| 杭州市| 开远市| 石城县| 泸州市| 昔阳县| 雷州市| 清水县| 句容市| 合江县| 郁南县| 民勤县| 商洛市| 札达县| 棋牌| 新河县| 青岛市| 韶山市| 筠连县| 新余市| 平凉市| 三亚市| 胶南市| 体育| 宜君县| 泰兴市|