[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Scroll to named hyperlink on page load

Posted on 2004-09-14
4
Medium Priority
?
610 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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