I have a 700 page website paged pg_0001 - pg_0700. And I figure to my knowledge in JavaScript and ASP ( unless you have an easier way ) I want to first read the existing pathname: document.write(location.pathname); Code (markup): Then somehow add +1 ( next page ) to the string or -1 ( previous page ) function prevLocation() { document.write(location.pathname); window.location="pg_0001<%'1%>.asp"; } function nextLocation() { document.write(location.pathname); window.location="pg_0001<%'1%>.asp"; } Code (markup): <a href="#" onclick="prevLocation();">Previous Page</a> <a href="#" onclick="nextLocation();">Next Page</a> Code (markup):
Why use javascript? use the ASP to get the current pages number and have the link as current number +1 or current number -1
Ok I have this so far: page=PageCount page = Request.ServerVariables("script_name") Code (markup): And then: href="<%response.Write(Replace(page, "002", "001"))%>" Code (markup): Hmmm... I don't know how to replace the three digits with a +/- 1.
if you have all the pages static, then javascript may be a good way to go. otherwise if you are retrieving the data from database, of course asp would be the better choice. you can do the paging in many ways: 1. retrieve all data, save in a session(not good for lot of data) then loop through to find the websites on that page. You can use the pagenumber on a session or Viewstate variable. 2. you can use a stored procedure to get the data only for the page you need. I suggest this one. to save the current page number best choice is viewstate. you can use session also.
Sure, thats good also. But you can do the whole think using javascript also without using asp. You can read the page number variable as you said, then call the document based on that.
This is the code to get querystring. Using this, you can find the currentpage. //==============START OF QUERYSTRING FUNCTIONS function PageQuery(q) { if(q.length > 1) this.q = q.substring(1, q.length); else this.q = null; this.keyValuePairs = new Array(); if(q) { for(var i=0; i < this.q.split("&").length; i++) { this.keyValuePairs = this.q.split("&"); } } this.getKeyValuePairs = function() { return this.keyValuePairs; } this.getValue = function(s) { for(var j=0; j < this.keyValuePairs.length; j++) { if(this.keyValuePairs[j].split("=")[0] == s) return this.keyValuePairs[j].split("=")[1]; } return false; } this.getParameters = function() { var a = new Array(this.getLength()); for(var j=0; j < this.keyValuePairs.length; j++) { a[j] = this.keyValuePairs[j].split("=")[0]; } return a; } this.getLength = function() { return this.keyValuePairs.length; } } //Call this function to get the querystring values function queryString(key) { var page = new PageQuery(window.location.search); return unescape(page.getValue(key)); } //============END OF QUERYSTRING FUNCTIONS function prevLocation() { if(queryString("currentPage")) { } window.location="pg_0001.asp"; } function nextLocation() { window.location="pg_0002.asp"; } //test alert(queryString("name")); //You have work on the Prev & NextLocation functions based on what you get on the querystring value. Hope that helps.
Where as we would do it all on ASP rather than javascript as you arent introducing a new journey back to the server and some people have javascript disabled therefore preventing your navigation from working If these are static pages, why arent you just putting the links in manually rather than trying to do it dynamically client or server side?