1、表單提交,
<form action= "target.aspx" method = "post" name = "form1">
<input name = "param1" value = "1111"/>
<input name = "param2" value = "2222 " /> 国产精品美女久久久久久久久 ,免费不卡毛片,黄色1级片.

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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

一、目前在ASP.NET中頁面傳值共有這么幾種方式:
1、表單提交,
<form action= "target.ASPx" method = "post" name = "form1">
<input name = "param1" value = "1111"/>
<input name = "param2" value = "2222"/> 
</form>
....
form1.submit();
....
此種方在ASPNET中無效,因為ASPNET的表單總是提交到自身頁面,如果要提交到別一頁面,需要特殊處理。
2、<A href="target.ASPx?param1=1111¶m2=2222">鏈接地址傳送</A>
接收頁面: string str = Request["param1"]
3、Session共享
發送頁面:Session("param1") = "1111"; 
按收頁面 string str = Session("param1").ToString(); 
4、Application共享
發送頁面: Application("param1") = "1111"; 
按收頁面: string str = Application("param1").ToString(); 
此種方法不常使用,因為Application在一個應用程序域范圍共享,所有用戶可以改變及設置其值,故只應用計數器等需要全局變量的地方。
5、Cookie
6、Response.Redirect()方式
Response.Redirect("target.ASPx?param1=1111¶m2=2222")
接收頁面: string str = Request["param1"]
7、Server.Transfer()方式。
Server.Transfer("target.ASPx?param1=1111¶m2=2222")
接收頁面: string str = Request["param1"]
二、如果在兩個頁面間需要大量的參數要傳傳遞,如數據查詢等頁面時,用1 - 6的方法傳值及其不便,而第 7 種方法確有一獨特的優勢!但使用該方法時需要一定的設置,現簡單介紹一下該方法的使用方式:
以查詢數據頁面為例:
在查詢頁面中設置如下公有屬性(QueryPage.ASPx): public class QueryPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtStaDate;
protected System.Web.UI.WebControls.TextBox txtEndDate;
/**//**//**//// <summary>
/// 開始時間
/// </summary>
public string StaDate
{
get{ return this.txtStaDate.Text;}
set{this.txtStaDate.Text = value;}
}
/**//**//**//// <summary>
/// 結束時間
/// </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來接收傳遞過來的參數
}
}
在顯示查詢結果頁面(ResultPage.ASPx):
public class ResultPage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{

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

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

1、先定義一個類,用該類放置所有查詢參數:(*.cs) /**//// <summary>
/// 結果頁面中要用到的值
/// </summary>
public class QueryParams
{
private string staDate;
private string endDate;

/**//**//**//// <summary>
/// 開始時間
/// </summary>
public string StaDate
{
get{ return this.staDate;}
set{this.staDate = value;}
}
/**//**//**//// <summary>
/// 結束時間
/// </summary>
public string EndDate
{
get{ return this.endDate;}
set{this.endDate = value;}
}
}
2、接口定義:
/**//// <summary>
/// 定義查詢接口。
/// </summary>
public interface IQueryParams
{
/**//**//**//// <summary>
/// 參數
/// </summary>
QueryParams Parameters{get;}
}
3、查詢頁面繼承IQueryParams接口(QueryPage.ASPx):
/**//// <summary>
///查詢頁面,繼承接口
/// </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>
/// 結果頁面用到的參數
/// </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、別外的頁面也如此設置

AspNet技術asp.net Context.Handler 頁面間傳值方法第1/2頁,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 成都屏蔽机柜厂| 幺红的个人简历| 小男孩王泓翔唱梨花颂| 奶粉过敏的症状和表现| 星河长明免费观看电视剧| 罪孽天使| 陕西卫视节目表| yy五项滚刀骂人套词| 黄视频免费观看网站| 拒不参加学校肺结核检查| 林莉娴| 漂亮孕妇肚子疼视频要生了| 尤克里里指弹谱| 同人视频| 陈颖芝三级| 故乡别来无恙演员表名单| 1998年槟榔西施| 性视频动态图| 纵情四海| 崔哲浩| 危险诱惑| 小数除法竖式50道带答案| 古天乐电影大全| hunger game| 新民歌| 金珊| 古灵精探演员表| 《继承者们》| 植树看图写话| 爱情岛论坛.| 防冲撞应急处置预案| 昌秀 电影| 我的冠军男友在线看全集完整| 张柏芝艳照无删减版| 三级女友| 卫平| 好男儿之情感护理| 全国第一小县| 座头市 电影| 美少女战士变身| 日本妈妈大电影|