Solved

Scroll to named hyperlink on page load

Posted on 2004-09-14
4
596 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now