Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Redirect question 2

Status
Not open for further replies.

zzfive03

Programmer
Jun 11, 2001
267
Is there a way so that when I load a page, I can have it jump to a particular line? For example, I have a tabel that re-sorts when you press the header row. But the table is far down on the screen. When the page refreshes, it takes me back to the top of the page. Can I some how pass my tables current line to the resubmit and have it scroll down to that location?

Thanks in advance
 
document.body.scrolltop is the property you are looking for.

It holds the vertical scroll position of your page. It's sort of a wierd property, being as it is readable and writeable (both a command and a query), and here's how I use it:

You say that your tables are sortable by clicking on a header cell, right? So that header cell, when clicked, calls a client side javascript function, yes?

Ok, then you need to put this hidden form element right at the end of your page:

<input type=hidden name=screenPosition>

Then, you will set it inside of your sort function right before you reload the page like this:

document.formName.screenPosition.value = document.body.scrolltop;

Then, go ahead and do your submit (the reload) -- and pick your value back up on the next load of the page and put it into a server side variable like this:

<%
dim screenPosition
screenPosition = request.form(&quot;screenPosition&quot;)
%>

And now, right at the end of your HTML (literally right before your </body> tag), put this bit of code:

<%
if screenPosition <> &quot;&quot; then%>
<script language=javascript>
document.body.scrolltop = <%=screenPosition%>;
</script>
<%
end if%>

So that if your server side ASP variable, screenPosition, has a value, then the line of client side code will be written, and your webpage will automatically be scrolled down to exactly where you left it when you clicked the table cell.

hope that helps! :)
Paul Prewett
penny.gif
penny.gif
 
I thought this subject would make an excellent FAQ, so I submitted one.

If my answer isn't clear, then check out faq333-1037 for more info.

:)
paul
penny.gif
penny.gif
 
pss. Watch my case mistakes in my reply up there. I fixed it in the FAQ.

Anywhere you see scrolltop -- make it scrollTop or it won't work.

Sorry for the confusion. I'm going to hush now.
penny.gif
penny.gif
 
It worked great, thanks for your help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top