新建一个实体类QueryParams 和一个接口:IQueryParams
实体类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for QueryParams
/// </summary>
public class QueryParams
{
public QueryParams()
{
//
// TODO: Add constructor logic here
//
}
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; }
}
}
接口:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for IQueryParams
/// </summary>
public interface IQueryParams
{
QueryParams Parameters { get; }
}
首页:中添加两个文本框和一个按钮:
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page, IQueryParams
{
private QueryParams queryParams;
public QueryParams Parameters{ get{ return queryParams;} }
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
queryParams = new QueryParams();
queryParams.StaDate = this.TextBox1.Text.ToString();
queryParams.EndDate = this.TextBox2.Text.ToString();
Server.Transfer("ResultPage.aspx");
}
}
ResultPage.aspx 接受传过来的值的页面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ResultPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
QueryParams queryParams = new QueryParams();
IQueryParams queryInterface;
//实现该接口的页面
if (Context.Handler is IQueryParams)
{
queryInterface = (IQueryParams)Context.Handler;
queryParams = queryInterface.Parameters;
}
Response.Write("StaDate:");
Response.Write(queryParams.StaDate);
Response.Write("<br/>EndDate:");
Response.Write(queryParams.EndDate);
}
}
实现了页面大数据量值的传递 这时候不用session