首页 新闻 赞助 找找看

Request.QueryString["Page"]是静态变量吗

0
悬赏园豆:5 [已解决问题] 解决于 2015-07-08 13:30

代码如下:
 //判断是否具有页面跳转的请求
            if (Request.QueryString["Page"] != null)
                MyCurrentPage = Convert.ToInt32(Request.QueryString["Page"]);

当点击下一页,下一页 ,页数比如说是5  (下一页的代码如下)
 //如果当前页面不是最后一页
            if (!MyPaged.IsLastPage)
                //设置"下一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
                this.btnNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage + 1);

我的疑问是当我点下一页的时候, 我有传Page的值,  但是当我重新查询 ,没有去点下一页 ,也就是并没有传page参数的时候, 代码 Request.QueryString["Page"]  依然可以获取到Page的值,  感觉这好像是静态变量一样,但是页面是没有静态变量一说的, 好奇怪, 这是什么原因呢 

或者说 

疑惑的是 ,我查询的时候 并没有用 Request.CurrentExecutionFilePath + "?Page=5); 这样子的语句,  但是Request.QueryString["Page"] 可以获取到值

zhengyingcan的主页 zhengyingcan | 初学一级 | 园豆:12
提问于:2014-08-29 21:04
< >
分享
最佳答案
0

你在CSDN问了。没有解决?

收获园豆:3
LiuKaiFa | 小虾三级 |园豆:1491 | 2014-08-30 14:41

你真牛,知道我CSDN问了,我自己解决了,Request.QueryString["Page"] 就相当于Viewstate ,我测试过

zhengyingcan | 园豆:12 (初学一级) | 2014-08-30 17:38
其他回答(4)
0

不是静态变量,是URL请求参数。你看下,你访问的页面地址里是否有"page="的内容?就是这个?

519740105 | 园豆:5810 (大侠五级) | 2014-08-29 21:32

我查询的时候 并没有用 Request.CurrentExecutionFilePath + "?Page=5); 这样子的语句,  但是Request.QueryString["Page"] 可以获取到值,  查询按钮是button按钮。  

支持(0) 反对(0) zhengyingcan | 园豆:12 (初学一级) | 2014-08-29 21:34

@zhengyingcan: this.btnNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage + 1);

支持(0) 反对(0) 519740105 | 园豆:5810 (大侠五级) | 2014-08-29 21:49

@519740105: 没有点这个按钮,是另外一个查询按钮,

支持(0) 反对(0) zhengyingcan | 园豆:12 (初学一级) | 2014-08-29 21:56
0

你的页面中有viewstate吗,查询是post提交吗?是不是页面进行状态保持了,导致一些页面参数被保存了,或者你的页面存在UpdatePanel

收获园豆:2
铁手三郎 | 园豆:311 (菜鸟二级) | 2014-08-29 22:17
0

重新查询的代码贴出来看看

jello chen | 园豆:7306 (大侠五级) | 2014-08-30 08:58

protected void AK_Click(object sender, EventArgs e)//最近记录
    {
        string strErr = "";
        if (CheckBif.Checked)//如果考虑是否离职
        {
            if (txtha81.Checked)
            {
                strErr += "ha81 = 1 and ";
            }
            else
            {
                strErr += "ha81 = 0 and ";
            }
        }
        strErr += " DATEDIFF(day,crd,getdate())<6 ";
        Session["strWherehpsn"] = strErr;
        BindData();
    }

 

 private void BindData()     {

        string strWhere = "";         if (Session["strWherehpsn"] != null && Session["strWherehpsn"].ToString() != "")         {             strWhere += Session["strWherehpsn"].ToString();             string sesql = "select *," + addwhere + " from Hpsn where " + strWhere + " order by no DESC ";             DataTable dt = Maticsoft.DBUtility.DbHelperSQL.Query(sesql).Tables[0];                       //创建分页类             PagedDataSource MyPaged = new PagedDataSource();             //设置数据源             MyPaged.DataSource = dt.DefaultView;             //允许分页             MyPaged.AllowPaging = true;             //设置每页显示的项数             MyPaged.PageSize = 5;             //定义变量用来保存当前页索引             int MyCurrentPage;             //判断是否具有页面跳转的请求             if (Request.QueryString["Page"] != null)                 MyCurrentPage = Convert.ToInt32(Request.QueryString["Page"]);             else                 MyCurrentPage = 1;             //设置当前页的索引             MyPaged.CurrentPageIndex = MyCurrentPage - 1;             //显示状态信息             this.Label46.Text = "当前页:" + MyCurrentPage.ToString() + "/" + MyPaged.PageCount;             //如果当前页面不是首页             if (!MyPaged.IsFirstPage)                 //设置"上一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值                 this.btnPre.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage - 1);             //如果当前页面不是最后一页             if (!MyPaged.IsLastPage)                 //设置"下一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值                 this.btnNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage + 1);             //进行数据绑定             showcount.Text = dt.Rows.Count.ToString();                ListView1.DataSource = MyPaged;             ListView1.DataBind();                    }

支持(0) 反对(0) zhengyingcan | 园豆:12 (初学一级) | 2014-08-30 09:49
0

你点击查询时,  地址还是Request.CurrentExecutionFilePath + "?Page=。。。 所以你的request.querystring["page"]依然是获取到的    .另外request 获取的是静态值, querystring  是去找浏览器(viewstate)拿值的 

许大虾 | 园豆:12 (初学一级) | 2014-09-03 10:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册