Solved

Scroll to named hyperlink on page load

Posted on 2004-09-14
4
606 Views
Last Modified: 2008-03-03
How do I cause the web page to scroll to a named hyperlink on page load?

I have an area on the page where a user uses a listbox to select sub-categories until they reach the desired level. Above this listbox I have a "bread crumb trail" of hyperlinks to the higher levels:

CurrentLevel : Rooty > Level 1 > Level 2 (Root, Level 1, Level 2 are hyperlinks back to this page)

[Listbox of subcategories for current selection] (subcategories for Level 2 in this example).

Since this "control" is towards the bottom of the page, when a user selects either the links, or a selection in the list box the page reloads and the page is positioned at the top.

I can get the hyperlinks to work by appending a #category to the link and adding a <a name=category></a> tag.

But how do I accomplish something similar when an entry in the listbox is selected (the listbox has AutoPostBack=true)

Thanks.
0
Comment
Question by:sirk_a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
allanau20 earned 250 total points
ID: 12059134
Hi sirk_a:

Try this:

    Page.RegisterStartupScript("GoToUsrCtrl", "<scriptlanguage='javascript'>self.location.href='#category'</script>")

on the where the listbox is triggered.  It will jump to where '#category' is placed on your page.

HtH.
0
 
LVL 9

Expert Comment

by:hismightiness
ID: 12059349
   Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Response.Redirect(Request.ServerVariables("script_name") & "#" & DropDownList1.SelectedValue)
    End Sub
0
 
LVL 5

Expert Comment

by:allanau20
ID: 12059510
I'm pretty sure that if you use response.redirect, you'll lose your viewstate.  Not sure if that's what you want.

However, if you use  Page.RegisterStartupScript you won't lose your viewstate.  Taking the above example, you can do this:

  Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Page.RegisterStartupScript("GoToUsrCtrl", "<scriptlanguage='javascript'>self.location.href='#category'</script>")
    End Sub

HtH.
0
 
LVL 3

Author Comment

by:sirk_a
ID: 12059749
allanau20 - Thank you. The RegisterStartupScript was what I needed.


 hismightiness - Since allanau20's worked I did not pursue yours. Although I would need viewstate maintained and I agree that the response.redirect would have lost that.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question