Click here to Skip to main content
15,917,062 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:

How can I perform a manual paging on class-array in client side? My aim is to show tourList[] records in pages with a limit of 10 records for per page. When I click the page numbers, the postback should occur and then bring the other records for clicked page.

I tried several ways but I couldn't succeed it because of HyperLinks for the page numbers. I even tried with the ASP:LINKBUTTON but whenever postback occurs, tourList[] becomes null. So I loose the tourList. :(

// the following the array of class is populated at server side. I successfully 
// display the all records but not in paging.

protected PSSaleWS.TourPackageSearchResultItem[] tourList;

if you show me how to solve the problem, I would really appreciate your help.

Sergey Alexandrovich Kryukov 2-May-11 13:01pm    
Hm. What is the class-array, please?
thatraja 2-May-11 14:59pm    
[Comment from OP]
An array which holds the class as shown above.
JUNEYT 2-May-11 13:14pm    
An array which holds the class as shown above.
Sergey Alexandrovich Kryukov 2-May-11 15:06pm    
Array of the instances of some class. Please say precisely to avoid ambiguous or unrecognized notions.
[no name] 2-May-11 16:47pm    
That's quite irrelevant. He mentioned, he loses the array between postbacks. We know why. He just needs to know more about the page lifecycle and the ViewState to get this working.

1 solution

The little code you have posted looks like a member variable, probably of your ASP .Net webpage. If that's so, it's not a good idea to work that way.

Why? That's easy. The page does not exist on the server between postbacks. At every request (including postbacks) a new instance of the page is created, performs a sequence of events and is destroyed when the response has been sent.

After a postback it's a new page where your array has never been filled. There are several things you should look at to better understand what's going on:

ASP.Net page lifecycle[^]

Data binding[^]

Alternatively, you can do manual paging and not use data binding. In this case you must store your array in the ViewState and restore it from there at every call to PageLoad(). Also, you must fill the control yourself after every postback. This should also be done at PageLoad(), right after restoring the array from the ViewState.

Share this answer
Sergey Alexandrovich Kryukov 2-May-11 16:58pm    
Popular, to the point and informative. My 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900