1、表單提交,
<form action= "target.aspx" method = "post" name = "form1">
<input name = "param1" value = "1111"/>
<input name = "param2" value = "2222 " /> 亚洲最新av,国产午夜精品麻豆,肉色欧美久久久久久久免费看

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

asp.net Context.Handler 頁(yè)面間傳值方法第1/2頁(yè)

一、目前在ASP.NET中頁(yè)面?zhèn)髦倒灿羞@么幾種方式:
1、表單提交,
<form action= "target.ASPx" method = "post" name = "form1">
<input name = "param1" value = "1111"/>
<input name = "param2" value = "2222"/> 
</form>
....
form1.submit();
....
此種方在ASPNET中無(wú)效,因?yàn)?a href=/itjie/ASPjishu/ target=_blank class=infotextkey>ASP。NET的表單總是提交到自身頁(yè)面,如果要提交到別一頁(yè)面,需要特殊處理。
2、<A href="target.ASPx?param1=1111¶m2=2222">鏈接地址傳送</A>
接收頁(yè)面: string str = Request["param1"]
3、Session共享
發(fā)送頁(yè)面:Session("param1") = "1111"; 
按收頁(yè)面 string str = Session("param1").ToString(); 
4、Application共享
發(fā)送頁(yè)面: Application("param1") = "1111"; 
按收頁(yè)面: string str = Application("param1").ToString(); 
此種方法不常使用,因?yàn)锳pplication在一個(gè)應(yīng)用程序域范圍共享,所有用戶(hù)可以改變及設(shè)置其值,故只應(yīng)用計(jì)數(shù)器等需要全局變量的地方。
5、Cookie
6、Response.Redirect()方式
Response.Redirect("target.ASPx?param1=1111¶m2=2222")
接收頁(yè)面: string str = Request["param1"]
7、Server.Transfer()方式。
Server.Transfer("target.ASPx?param1=1111¶m2=2222")
接收頁(yè)面: string str = Request["param1"]
二、如果在兩個(gè)頁(yè)面間需要大量的參數(shù)要傳傳遞,如數(shù)據(jù)查詢(xún)等頁(yè)面時(shí),用1 - 6的方法傳值及其不便,而第 7 種方法確有一獨(dú)特的優(yōu)勢(shì)!但使用該方法時(shí)需要一定的設(shè)置,現(xiàn)簡(jiǎn)單介紹一下該方法的使用方式:
以查詢(xún)數(shù)據(jù)頁(yè)面為例:
在查詢(xún)頁(yè)面中設(shè)置如下公有屬性(QueryPage.ASPx): public class QueryPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtStaDate;
protected System.Web.UI.WebControls.TextBox txtEndDate;
/**//**//**//// <summary>
/// 開(kāi)始時(shí)間
/// </summary>
public string StaDate
{
get{ return this.txtStaDate.Text;}
set{this.txtStaDate.Text = value;}
}
/**//**//**//// <summary>
/// 結(jié)束時(shí)間
/// </summary>
public string EndDate
{
get{ return this.txtEndDate.Text;}
set{this.txtEndDate.Text = value;}
}

private void btnEnter_Click(object sender, System.EventArgs e)
{
Server.Transfer("ResultPage.ASPx"); //注意:使用ResultPage.ASPx來(lái)接收傳遞過(guò)來(lái)的參數(shù)
}
}
在顯示查詢(xún)結(jié)果頁(yè)面(ResultPage.ASPx):
public class ResultPage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{

//轉(zhuǎn)換一下即可獲得前一頁(yè)面中輸入的數(shù)據(jù)
QueryPage queryPage = ( QueryPage )Context.Handler;    //注意:引用頁(yè)面句柄

Response.Write( "StaDate:" );
Response.Write( queryPage.StaDate );
Response.Write( "<br/>EndDate:" );
Response.Write( queryPage.EndDate );
}
}
三、如果有許多查詢(xún)頁(yè)面共用一個(gè)結(jié)果頁(yè)面的設(shè)置方法:
在這種方式中關(guān)鍵在于“ QueryPage queryPage = ( QueryPage )Context.Handler; ”的轉(zhuǎn)換,只有轉(zhuǎn)換不依賴(lài)于特定的頁(yè)面時(shí)即可實(shí)現(xiàn)。
如果讓所有的查詢(xún)頁(yè)面都繼承一個(gè)接口,在該接口中定義一個(gè)方法,該方法的唯一作用就是讓結(jié)果頁(yè)面獲得構(gòu)建結(jié)果時(shí)所需的參數(shù),就可實(shí)現(xiàn)多頁(yè)面共享一個(gè)結(jié)果頁(yè)面操作!

1、先定義一個(gè)類(lèi),用該類(lèi)放置所有查詢(xún)參數(shù):(*.cs) /**//// <summary>
/// 結(jié)果頁(yè)面中要用到的值
/// </summary>
public class QueryParams
{
private string staDate;
private string endDate;

/**//**//**//// <summary>
/// 開(kāi)始時(shí)間
/// </summary>
public string StaDate
{
get{ return this.staDate;}
set{this.staDate = value;}
}
/**//**//**//// <summary>
/// 結(jié)束時(shí)間
/// </summary>
public string EndDate
{
get{ return this.endDate;}
set{this.endDate = value;}
}
}
2、接口定義:
/**//// <summary>
/// 定義查詢(xún)接口。
/// </summary>
public interface IQueryParams
{
/**//**//**//// <summary>
/// 參數(shù)
/// </summary>
QueryParams Parameters{get;}
}
3、查詢(xún)頁(yè)面繼承IQueryParams接口(QueryPage.ASPx):
/**//// <summary>
///查詢(xún)頁(yè)面,繼承接口
/// </summary>
public class QueryPage : System.Web.UI.Page, IQueryParams
{
protected System.Web.UI.WebControls.TextBox txtStaDate;
protected System.Web.UI.WebControls.TextBox txtEndDate;

private QueryParams queryParams;

/**//**//**//// <summary>
/// 結(jié)果頁(yè)面用到的參數(shù)
/// </summary>
public QueryParams Parameters
{
get
{
return queryParams;
}
}

private void btnEnter_Click(object sender, System.EventArgs e)
{
//賦值
queryParams = new QueryParams();
queryParams.StaDate = this.txtStaDate.Text;
queryParams.EndDate = this.txtEndDate.Text

Server.Transfer("ResultPage.ASPx");
}
}
4、別外的頁(yè)面也如此設(shè)置

AspNet技術(shù)asp.net Context.Handler 頁(yè)面間傳值方法第1/2頁(yè),轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 绥棱县| 喜德县| 富源县| 太白县| 镇原县| 双峰县| 乌苏市| 顺昌县| 桂东县| 定襄县| 潮州市| 乐平市| 塔城市| 岳普湖县| 新乡县| 博野县| 竹北市| 北碚区| 日照市| 尚义县| 怀化市| 宝山区| 梁平县| 陆丰市| 师宗县| 资溪县| 宁夏| 巨野县| 砚山县| 明水县| 吉木萨尔县| 新津县| 纳雍县| 荥经县| 高青县| 茌平县| 安岳县| 徐水县| 望谟县| 项城市| 平塘县|