QueryString 页面传值方法

Request Response 是两个非常重要而且有用的对象。Request 是请求对象,它存储客户端的信息。Response 是服务器对象,它包售服务器的响应。

该示例包括两个页面:SendQueryString.aspx QueryString.aspx 。将在SendQueryString.aspx中传递值给QueryString.aspx,然后在QueryString 中读取数据。这是一种页面传值的方法。

1SendQueryString.aspx Page_Load 中添加如下代码:

public partial class SendQueryString : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        //传递国家,省份,市信息给QueryString.aspx

        this.Response.Redirect("QueryString.aspx?Country=\"China\"&&province=\"HuNan\"&&City=\"ChangSha\"");

    }

}

2QueryString.aspx中读取QueryString信息:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class QueryString : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        //读取QueryString.aspx信息

        string country = this.Request.QueryString["Country"].ToString().Trim();

        string provinc = this.Request.QueryString["Province"].ToString().Trim();

        string city = this.Request.QueryString["City"].ToString().Trim();

        //显示QueryString信息

        this.Response.Write("传递过来的信息:国家="+country+"省份="+provinc+"城市="+city);

    }

}

 

3 结果为:传递过来的信息:国家="China"省份="HuNan"城市="ChangSha"

转载于:https://www.cnblogs.com/fanghui/archive/2012/08/20/2774278.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值