Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HistoryPoint doesn't work after hyperlink clicked and come back with ListView sorted

Posted on 2008-09-29
1
Medium Priority
?
528 Views
Last Modified: 2013-11-08
Hi, I have a ListView putted inside UpdatePanel which can be sorted and paged. HistoryPoint works only in the page itself, but once I clicked the link in the row of the ListView to go to a different page and come back, the last history point is not the point I left. I inserted the code AddHistoryPoint to LinkButton_dClicke event method so that once the link was clicked, the history point is created with the page number and sorted column name and sort method(ascending or desending). But when I come back to the ListView from the detail page, it doesn't show  the list that I left. Here are the codes;


private void AddHisotryPointAmount(string sortExpression, SortDirection sortDirection)
    {
        if (ScriptManager1.IsInAsyncPostBack && !ScriptManager1.IsNavigating)
        {
            string v = string.Empty;
            if (sortDirection == SortDirection.Ascending)
                v = "ASC:" + sortExpression;
            else
                v = "DES:" + sortExpression;
 
            v += "PAGENUM:" + DataPager1.StartRowIndex;
            ScriptManager1.AddHistoryPoint("A", v);
        }
    }
 
 
    protected void ScriptManager1_Navigate(object sender, HistoryEventArgs e)
    {
        int cState = e.State.Keys.Count;
        if (cState < 1)
        {
            //the list is in initial state. never sorted or paged. 
        }
        else
        {
           // string lastStateKey = e.State.Keys[cState-1];
            //string lastStateValue = e.State[lastStateKey];
            string lastStateKey = e.State.Keys[0];
            string lastStateValue = e.State[0];
 
            if (lastStateKey == "P")
            {
                int pageNum = Int32.Parse(lastStateValue);
                DataPager1.SetPageProperties(pageNum, DataPager1.PageSize, true);
            }
            else if (lastStateKey == "S")
            {
                string sortExpression = string.Empty;
                if (lastStateValue.IndexOf("ASC:") > -1)
                {
                    sortExpression = lastStateValue.Substring(lastStateValue.IndexOf("ASC:") + 4);
                    ListView1.Sort(sortExpression, SortDirection.Ascending);
                }
                else if (lastStateValue.IndexOf("DES:") > -1)
                {
                    sortExpression = lastStateValue.Substring(lastStateValue.IndexOf("DES:") + 4);
                    ListView1.Sort(sortExpression, SortDirection.Descending);
                }
            }
            else if (lastStateKey == "A")
            {
                string sortExpression = string.Empty;
                if (lastStateValue.IndexOf("ASC:") > -1)
                {
                    sortExpression = lastStateValue.Substring(lastStateValue.IndexOf("ASC:") + 4, lastStateValue.IndexOf("PAGENUM:")-(lastStateValue.IndexOf("ASC:") + 4));
                    ListView1.Sort(sortExpression, SortDirection.Ascending);
                }
                else if (lastStateValue.IndexOf("DES:") > -1)
                {
                    sortExpression = lastStateValue.Substring(lastStateValue.IndexOf("DES:") + 4, lastStateValue.IndexOf("PAGENUM:") - (lastStateValue.IndexOf("DES:") + 4));
                    ListView1.Sort(sortExpression, SortDirection.Descending);
                }
                int pageNum = Int32.Parse(lastStateValue.Substring(lastStateValue.IndexOf("PAGENUM:")+8));
                DataPager1.SetPageProperties(pageNum, DataPager1.PageSize, true);
            }
            else { }
            
        }
        
    }
 
 
 
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        try
        {
            LinkButton lnkTotalCondidate = (LinkButton)e.CommandSource;
            LinkButton lnkTotal = (LinkButton)e.Item.FindControl("lnkTotal");
 
            if (lnkTotalCondidate.ID == lnkTotal.ID)
            {
                AddHisotryPointAmount(ListView1.SortExpression,ListView1.SortDirection);
                Response.Redirect("SingleReceipt.aspx?ResNo=" + lnkTotal.Attributes["ResNo"]);
            }
        }
        catch (Exception ex)
        {
            ;
        }
        
    }

Open in new window

0
Comment
Question by:crcsupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
crcsupport earned 0 total points
ID: 22602946
I solved the problem. I had to insert historypoint for both paging and sorting everytime no matter what action(paging, sorting, leaving the page to another page).  I like AJAX how they work with no flash, but sometimes it's very headache to find bug when coding.
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question