复制代码 代码如下:
/**//// <summary>
/// QueryParams 的摘要说明
/// </summary>
public class QueryParams
{
private string firstName;
private string lastname;
private int age;
public string Firstname
{
get { return this.firstname; }
set { this.firstname = value; }
}
public string LastName
{
get { return this.lastname; }
set { this.lastname = value; }
}
public string Age
{
get { return this.age; }
set { this.age = value; }
}
}
复制代码 代码如下:
/**//// <summary >
/// 定义查询接口。
/// </summary >
public interface IQueryParams
{
/**//// <summary >
/// 参数
/// </summary >
QueryParams Parameters { get;}
}
复制代码 代码如下:
<form runat="server">
<div>
<asp:TextBox runat="server"></asp:TextBox>
<asp:TextBox runat="server"></asp:TextBox>
<asp:TextBox runat="server"></asp:TextBox>
<asp:Button runat="server" Text="Button" /></div>
</form>
复制代码 代码如下:
public partial class QueryPage : System.Web.UI.Page, IQueryParams
{
private QueryParams queryParams;
public QueryParams Parameters
{
get
{
return queryParams;
}
}
public void btnEnter_Click(object sender, System.EventArgs e)
{
//赋值
queryParams = new QueryParams();
queryParams.FirstnName = this.txtFirstName.Text;
queryParams.Lastname = this.txtLastName.Text;
queryParams.Age = this.txtAge.Text;
Server.Transfer( "ResultPage.aspx ");
}
protected void Page_Load(object sender, EventArgs e)
{ }
}
复制代码 代码如下:
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("FirstName: ");
Response.Write(queryParams.FirstName);
Response.Write(" <br/ >Lastname: ");
Response.Write(queryParams.LastName);
Response.Write(" <br/ >Age: ");
Response.Write(queryParams.Age);
}
}
新闻热点
疑难解答
图片精选