After page loads, how do I make it scroll to a certain position?

M

moondaddy

I will be loading a page using a redirect like this:

response.Redirect("Address.aspx?CalledFrom=Payment.aspx&SectionToUpdate=Bill
ing", False)

When Address.aspx loads, I need to scroll it down to the Billing address
section.

I created a bookmark down by the Billing section where I want to scroll to
like this:

<A name="myGoodBK">

I know I can create an href element that would goto this bookmark, but that
would require the user to click on the href. how can I do this via jscript
with out any user click events?
 
M

moondaddy

I partially solved my problem, but I would still like to know how to call a
bookmark (or hyperlink) by jscript. But this is how I got the page to
scroll to the bookmark after loading

response.Redirect("Address.aspx?CalledFrom=Payment.aspx&SectionToUpdate=Bill
ing&#myBK", False)

where myBK is the name of the bookmark on the page.

Now one more thing. When the page loads you see it scrolled all the way to
the top like normal, then after a split second it scrolls to the bookmark.
I've seen other sites load pages directly to the bookmark so you don't see
it scroll after it loads which is much cleaner. how can I have the page
already scrolled to the bookmark before it actually displays for the user?
 
S

Saravana [MVP]

Try SmartNavigation, check out the following link for more details
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWebUIPageClassSmartNavigationTopic.asp



--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com



moondaddy said:
I partially solved my problem, but I would still like to know how to call a
bookmark (or hyperlink) by jscript. But this is how I got the page to
scroll to the bookmark after loading

response.Redirect("Address.aspx?CalledFrom=Payment.aspx&SectionToUpdate=Bill
ing&#myBK", False)

where myBK is the name of the bookmark on the page.

Now one more thing. When the page loads you see it scrolled all the way to
the top like normal, then after a split second it scrolls to the bookmark.
I've seen other sites load pages directly to the bookmark so you don't see
it scroll after it loads which is much cleaner. how can I have the page
already scrolled to the bookmark before it actually displays for the user?



--
(e-mail address removed)
moondaddy said:
I will be loading a page using a redirect like this:
response.Redirect("Address.aspx?CalledFrom=Payment.aspx&SectionToUpdate=Bill
 
S

Steven Cheng[MSFT]

Thanks for Saravana's suggestion on "SmartNavigation"

Hi Moondaddy,

I think you may have a look at the smartNavigation Saravana has mentioned.

In addition, As for the question "how to let a page scroll to a certain
anchor <A name="myGoodBK"> when loaded", I think you can also try the
following means:
1. use the window.location.href = "the page's url#anchorname"

2. add a unvisible hyperlink tag in page and use javascript to fire the
link's click event. For example:
<a id="lnkAnchor" href="#myGoodBK" ></a>

then use the following code when the page is loaded at client
<body onload='document.getElementById("lnkAnchor").click()' >

thus, the "lnkAnchor" 's click event will be fired when page is loaded and
be scroll to the <A name="myGoodBK">'s position.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
M

moondaddy

Thanks. I think the line of code below:

document.getElementById("lnkAnchor").click()

was the main missing link in what I needed. Because I don't want the page
to scroll to this bookmark all the time but rather only if certain server
side conditions exist, I'll need to call that line by executing some jscript
generated by the server when appropriate using
Page.RegisterClientScriptBlock("clientScript", scriptString).

Thanks for the help to both you and Saravana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top