By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Save scroll position AND setFocus

P: n/a
JC
I'm sure you've all seen the save scroll position from 4 guys from
rolla which can be found here >
http://aspnet.4guysfromrolla.com/articles/111704-1.aspx
BUT
try to get that to work AND still be able to set the focus to a
control.

Here's the problem, when you set the focus by using the
registerstartupscript method the control gets the focus after the
scroll position has been set. When this happens the scroll position
gets set a second time but it sets the focused control at the bottom
of your page.
To test-
(you would need the scroll position code from the 4 guys site)
Build a page with a whole lot of <br>'s and in the middle put a
textbox and at the end put a button. In the button call

RegisterStartupScript("focus", "<script language=""JavaScript"">" &
vbCrLf & vbTab & "document.getElementById('TextBox3').focus();" &
vbCrLf & "<" & "/script>")

I want my page to stay scrolled to the bottom but it scrolls to the
point of the textbox.

Any ideas on how to fix this would be AMAZINGLY appreciated. I don't
need to use this code just need it to work.
No, smartnavigation will not work since you can not focus with that
either
(or if you can, let me know but I'd rather not use it)

contact me at the e-mail or at ujjc001@ on my gmail account but please
post here too for others to share.
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
you need to set the focus after the scroll has happened. your focus scroll
changes the saved coordinates. there scroll happens at onload, and you need
to let the window scroll happen first. change their code to something like:

function sstchur_SmartScroller_Scroll()
{
var x = document.forms[formID].xCoordHolder.value;
var y = document.forms[formID].yCoordHolder.value;
document.forms[formID].focusHolder.value;
window.scrollTo(x, y);

window.setTimeout("document.forms[document.forms[formID].focusHolder.value].
focus()",10);
}

where you store the focus field name in focusHolder
-- bruce (sqlwork.com)
"JC" <uj*****@charter.net> wrote in message
news:b8**************************@posting.google.c om...
| I'm sure you've all seen the save scroll position from 4 guys from
| rolla which can be found here >
| http://aspnet.4guysfromrolla.com/articles/111704-1.aspx
| BUT
| try to get that to work AND still be able to set the focus to a
| control.
|
| Here's the problem, when you set the focus by using the
| registerstartupscript method the control gets the focus after the
| scroll position has been set. When this happens the scroll position
| gets set a second time but it sets the focused control at the bottom
| of your page.
| To test-
| (you would need the scroll position code from the 4 guys site)
| Build a page with a whole lot of <br>'s and in the middle put a
| textbox and at the end put a button. In the button call
|
| RegisterStartupScript("focus", "<script language=""JavaScript"">" &
| vbCrLf & vbTab & "document.getElementById('TextBox3').focus();" &
| vbCrLf & "<" & "/script>")
|
| I want my page to stay scrolled to the bottom but it scrolls to the
| point of the textbox.
|
| Any ideas on how to fix this would be AMAZINGLY appreciated. I don't
| need to use this code just need it to work.
| No, smartnavigation will not work since you can not focus with that
| either
| (or if you can, let me know but I'd rather not use it)
|
| contact me at the e-mail or at ujjc001@ on my gmail account but please
| post here too for others to share.
Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.