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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MaintainScrollPositionOnPostback

Status
Not open for further replies.

dstrange

Programmer
Nov 15, 2006
87
CA
This works great when a page hits a postback but is there a way for this option to work if I click a link on the page that reposts to the same url but with a querystring attached? Thanks in advance.
 
Something like this?

All the <br /> tags are create a scroll bar (quick and dirty way).

The onload event needs to grab the value from the qs using what ever server side language you are using (i.e)

Code:
<body onload="scrollTo(<%=request.querystring("vScroll")%>">

PHP:
<body onload="scrollTo(<%?php $_GET["vScroll"] ?>">

Here's one solution for the scrolling

Code:
<html>
<head>
<script language="javascript">
	function goToUrl(strInput) {
		vScrollPos = document.body.scrollTop;
		document.location.href = strInput + "?vScroll=" + vScrollPos;
		return false;
	}
	function scrollTo(intScrollPos) {
		document.body.scrollTop = intScrollPos;
	}
</script>
</head>
<body onload="scrollTo(valueFromQueryString);">
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<a href="myUrl" onclick="return goToUrl('test.html');" >Click</a>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</html>

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top