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、別外的頁面也如此設置
12下一頁閱讀全文
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com