Solved

Scroll to named hyperlink on page load

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Emulate" TAB key when press Enter Key 3 91
C# MVC Insert Multiple Row into DB 2 93
disadvantage of code behind appoarch in asp.net 3 47
How does this modal work? 3 33
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

739 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