推薦:ASP.NET生成靜態網頁的方法環境:Microsoft .NET Framework SDK v1.1OS:Windows Server 2003 中文版ASP.Net生成靜態HTML頁,在Asp中實現的生成靜態頁用到的FileSystemObject對象,在.Net中涉及此類操作的是System.IO
一、目前在ASP.NET中頁面傳值共有這么幾種方式:
1、表單提交
<form action= "target.aspx" method = "post" name = "form1">
<input name = "param1" value = "1111"/>
<input name = "param2" value = "2222"/>
</form>
....
form1.submit();
....
此種方在ASP。NET中無效,因為ASP。NET的表單總是提交到自身頁面,如果要提交到別一頁面,需要特殊處理。
2、鏈接地址傳送
接收頁面: 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):
| 以下為引用的內容: public class ResultPage : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { //轉換一下即可獲得前一頁面中輸入的數據 Response.Write( "StaDate:" ); |
分享:如何以及為何創建Search .NET版Search 開發負責人 Larry Jordan、開發人員 Michael Ruggiero 和 Michael Stanton 以及 .NET 框架項目經理 Hari Sekhar 在暗中構建了基于 .NET 技術的 Microsoft Web 站點搜索引擎新版
新聞熱點
疑難解答
圖片精選