0

如果我通过搜索,然后转到第 3 页的资源(查看链接),然后在浏览器上点击“返回”,它只会再次返回搜索的第一页。

private void BindResourcesRepater()
        {

            string tag = Request.QueryString["tag"];
            if (String.IsNullOrEmpty(tag))
            {

                //Guid userID = Guid.Parse(Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString());
                DataSet ds = new DataSet();
                int selectedTopicID = Convert.ToInt32(ddlTopics.SelectedValue);
                int selectedSkillID = Convert.ToInt32(ddlSkills.SelectedValue);
                int selectedTypeID = Convert.ToInt32(ddlTypes.SelectedValue);
                string keyword = txtbKeyword.Text.Trim();
                int sortBy = Convert.ToInt32(ddlSortBy.SelectedValue);
                ds = Resource.Search_Resource(selectedTopicID, selectedSkillID, selectedTypeID, keyword, sortBy);




                PagedDataSource objPds = new PagedDataSource();
                objPds.DataSource = ds.Tables[0].DefaultView;

                objPds.AllowPaging = true;

                objPds.PageSize = 6;


                int curpage;

                if (ViewState["Page"] != null)
                {
                    curpage = Convert.ToInt32(ViewState["Page"]);
                }
                else
                {
                    ViewState["Page"] = 1;
                    curpage = 1;
                }
                // Set the currentindex
                objPds.CurrentPageIndex = curpage - 1;



                rp_resList.DataSource = objPds;
                rp_resList.DataBind();

                if (rp_resList.Items.Count == 0)
                {
                    lnkNext.Visible = false;
                    if (Convert.ToInt32(ViewState["Page"]) == 1)
                    {
                        lnkPrev.Visible = false;
                    }
                    else
                    {
                        lnkNext.Visible = false;
                    }
                }


                else
                {
                    lnkNext.Visible = true;
                    if (rp_resList.Items.Count < objPds.PageSize)
                    {
                        lnkNext.Visible = false;
                    }

                    if (Convert.ToInt32(ViewState["Page"]) == 1)
                    {
                        lnkPrev.Visible = false;

                    }
                    else
                    {
                        lnkPrev.Visible = true;
                    }
                }

                int numberOfItems = ds.Tables[0].Rows.Count;
                lbl_totalResult.Text = GetCurrentVisibleItemsText(numberOfItems, objPds.PageSize, objPds.CurrentPageIndex);
            }
            else
            {
                DataSet ds = new DataSet();
                int selectedTopicID = Convert.ToInt32(ddlTopics.SelectedValue);
                int selectedSkillID = Convert.ToInt32(ddlSkills.SelectedValue);
                int selectedTypeID = Convert.ToInt32(ddlTypes.SelectedValue);
                txtbKeyword.Text = tag;
                string keyword = tag.ToString();
                int sortBy = Convert.ToInt32(ddlSortBy.SelectedValue);
                ds = Resource.Search_Resource(selectedTopicID, selectedSkillID, selectedTypeID, tag, sortBy);
                rp_resList.DataSource = ds.Tables[0];
                rp_resList.DataBind();


            }
        }
protected void lnkNext_Click(object sender, EventArgs e)
{
    // Set viewstate variable to the next page
    ViewState["Page"] = Convert.ToInt32(ViewState["Page"]) + 1;

    // reload the control
    BindResourcesRepater();
}
protected void lnkPrev_Click(object sender, EventArgs e)
{
    if (Convert.ToInt32(ViewState["Page"]) > 1)
    {
        // Set viewstate variable to the previous page
        ViewState["Page"] = Convert.ToInt32(ViewState["Page"]) - 1;
        // reload the control

    }
    BindResourcesRepater();
}
4

1 回答 1

0

正如我怀疑并在评论中发布的那样,您正在使用 UpdatePanels。

也许这可以帮助你:

如何在 UpdatePanel 中保存历史记录?

于 2013-07-18T13:54:05.627 回答