troubleshooting Question

AJAX and AddHistoryPoint not refreshing GridView

Avatar of dtburdick
dtburdickFlag for United States of America asked on
.NET ProgrammingASP.NET
2 Comments1 Solution738 ViewsLast Modified:
I am new to AJAX and AddHistoryPoint, so bear with me.

I have a GridView with a LinkButton in it.  When the user clicks the link they navigate to another page using Response.Redirect.  When they click the back button in the browser they come back to a page without the GridView rather than the page with the results as they were.  I gather this is common.

I've found examples with sorting and paging, but I am not using that, so I'm not sure what I'm supposed to use during the AddHistoryPoint to get it to remember the state of the GridView.

It hits the line of code with AddHistoryPoint, but it's not actually adding it.  No matter what I put in for the title it doesn't show up in the history.

What I have done is:

1) Set the ScriptManager EnableHistory to True
2) Add the following code:

    protected void MainScriptManager_Navigate(object sender, HistoryEventArgs e)
    {
        // Get GridView PagIndex from history
        string pageIndex = e.State["PageIndex"];
        if (string.IsNullOrEmpty(pageIndex))
        {
            gv_report.PageIndex = 0;
        }
        else
        {
            gv_report.PageIndex = Convert.ToInt32(pageIndex);
        }
    }

3) Added the following code to the GridView RowCommand:

    if (MainScriptManager.IsInAsyncPostBack && !MainScriptManager.IsNavigating)
    {
       MainScriptManager.AddHistoryPoint("pageIndex", gv_report.PageIndex.ToString(), "Reports");
    }
               
Response.Redirect("org.aspx?oid=" + Encryption64.EncryptQueryString(dk.Values["organization_id"].ToString(), ConfigurationManager.AppSettings["encryptionString"]));
ASKER CERTIFIED SOLUTION
EE_AutoDeleter

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros