views:

297

answers:

3

I have a record set with hundreds of rows. when a user clicks the row they go somewhere else and later get redirected to the page with the rows again. I want the page to start on the exact row the clicked on.

I have rows set up with a line number corresponding to each record number from the database.

//some record set

while not RS.eof

<a name="<%=line%>">
//other stuff

Rs.movenext
   Line = line + 1
wend

when you put '#' in the url and a number it goes to the line number. However, my issue is that the url is off limits. I have the line number stored as a Session variable that happens after they initially leave the page. How can i get the page to go to the line number using the session variable and not the url?

+2  A: 

As far as I know, anchor names are a feature of the browser. But there are possibly some Javascript libraries that can scroll down to an anchor name without needing the url.

Here's an SO Question on how to programatically scroll down to a certain location.

I think this works also but I haven't tested it

window.location.hash = "#anchorname";
Ólafur Waage
+1 great answer! thanks!
Eric
+2  A: 

If you can't do anything with the URL, your best (only) bet is JavaScript on the client.

function scrollTo(row) {
  window.location.hash = "#" + row;
}

And call that in body.onload, for example. Put the value of your session variable into the function call.

Tomalak
+1  A: 

I don't think you need anchors for this. You can capture the scroll position as a post a request variable and set it back with JavaScript in the page load.

The second option in the post is not specific to asp.net.
http://www.4guysfromrolla.com/articles/111704-1.aspx

jms
Scroll position is kinda useless if the page itself changes, yet the specific position should still be targeted. Other than that, nice trick. +1
Tomalak