how can i get the same page with the click of back button of browser

后端 未结 1 1062
孤独总比滥情好
孤独总比滥情好 2020-12-01 22:59

i am using asp.net with c# in my aspx page i have an update panel in this panel i have some links to other sites, which is open on the same window. after clicking on these l

1条回答
  •  执笔经年
    2020-12-01 23:44

    I have implement the same with the following Article, If you need further help, Plz let me know, I will provide chucks of code

    http://rchern.wordpress.com/2008/05/11/updatepanel-backforward-browser-navigation/

    First of all you have to Enable ScriptManager history EnableHistory="true"
    In this example we are maintaing gridview paging, When user browser back button You have add history point after your page first time loads.

    private void AddHistoryPoint(String key, String value, String tile)
    {
        ScriptManager scm = ScriptManager.GetCurrent(this.Page);
        if ((scm.IsInAsyncPostBack == true) && (scm.IsNavigating != true))
        {
            if (pageState == null)
            {
               NameValueCollection pageState = new NameValueCollection();
            }
            if (pageState[key] != null)
            {
                pageState[key] = value;
            }
            else
            {
                pageState.Add(key, value);
            }
            scm.AddHistoryPoint(pageState, tile);
        }
    }
    
    protected void grid_PageIndexChanged1(object sender, EventArgs e)
    {
        AddHistoryPoint("pi", grdProject.PageIndex.ToString(), "Page Index- " + (grdProject.PageIndex + 1).ToString());
    }
    



    here you have to handle ScriptManager Navigate Event

         protected void ScriptManager1_Navigate(object sender, System.Web.UI.HistoryEventArgs e)
    {
        if (e.State != null)
        {
            if (e.State["pi"] != null)
            {
                grid.PageIndex = Convert.ToInt32(e.State["pi"]);
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题