Search engine logic with pagination, working with large result set
<p>i've got a website with internal search engine that searches for users with specific parameters like age, height.... There are thousands of users so i've decided to use advanced CTE in order to retrieve 10 records each time to reduce load on MSSQL server.</p>

<p>In this CTE i get results by pages (ie. 10 records per page) while ordering it by lastVisit of user.</p>

<p>Problem is that i can't use default asp.net built it pager control so i've made mine which works fine but i need to get amount of pages in whole result set each time search is generated thus i first get result set and then max number of records so i can divide it by 10 to get latest page number to use in my pager controller.</p>

<p>so each time page loads two db calls are made, while i want to avoid needless amount of records when user just switches a page with same search parameters.</p>

<p>How would you advice to do that ?</p>
