Solved

How do you return to a specific location on a page after leaving the page using a NavigateURL?

Posted on 2011-09-23
10
211 Views
Last Modified: 2013-11-19
I have a Repeater on Page1.aspx which uses the NavigateURL property to jump to Page2.aspx which displays detail information associated with the item in the Repeater. I am able to return to PAGE1.aspx from Page2.aspx, but I return at the top of my Repeater list. Is there a way to return to the location in the list from which I left?
0
Comment
Question by:Donna Kainer
[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
  • 4
  • 4
  • 2
10 Comments
 
LVL 25

Expert Comment

by:Rouchie
ID: 36592178
You can link to an HTML element with a particular ID value.  So, to jump to a certain H2 heading on page2 you would write

<h2 id="index123">Heading 123</h2>

Then in page1 you would create your links to look like this:

<asp:HyperLink runat="server" ID="lnk1" NavigateUrl="page2.aspx#index123" Text="Link Text" />
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36592744
I think the idea about #index123 is on the right track, however I have always seen this used with the anchor tag instead of the id attribute of the h2 tag.

I would probably try it this way:

<a name="index123">
<h2 id="whatever">Heading 123</h2>
</a>
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 36594912
NAME is no longer supported in XHTML and above, which is why I opt for ID now, which has to be referenced within anchor tags using #
0
ClickHouse in a General Analytical Workload

We have mentioned ClickHouse in some recent posts, where it showed excellent results.

In this article on Experts Exchange, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36595207
Good point.  Technology is always advancing!
http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id
0
 

Author Comment

by:Donna Kainer
ID: 36601042
As a newbee some of this discussion is going over my head.

Page1.asp contains a Repeater which lists over 200 rows of information. On each row a NavigateURL that point to Page2.asp?Cust_Code=codevalue.

When you click on one of the values in a Repeater row on Page1.asp you are taken to Page2.asp which is opened containing the detail information concerning Cust_Code=codevalue.

The first response from Rouchie is interesting, but I am not trying to jump from Page1 to a specific place in Page2. What I am trying to do is jump from a specific place on Page1, which is generated by a Repeater, to Page2 (which shows the detail) and then I want to return to the place within the Repeater on Page1 from which I left.

An example of what I am trying to do would be something like a job posting website. You are presented with a list of jobs from which to chose. If you click on one, you go to the detail for that job. After reviewing the detail you return to the first web page, which contains the list of job postings, at the location in the list of job postings containing the specific posting you were looking at. Their method of providing the list may be more complex than can be accomodiated using a Repeater. If so, please offer some suggestions or links, that a newbee can understand, on how to accomplish this slight of hand.
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 36890389
Sorry for the delay, I have been away all week.

Before I show the ASP.NET method (that I would use), you might also try the javascript BACK trick.  Because the BACK command in the browser always returns the user to the part of the page where they left, this might work.  In page2.aspx, remove the NavigateUrl property that sends them to page1.aspx, and replace it with something like this:

<asp:HyperLink ID="MyLinkOnPage2" runat="Server" NavigateUrl="#" onclick="onClick="history.go(-1)" Text="Back" />

Open in new window


If that doesn't work, what you need to do is reference the current ID of the hyperlink on page1, pass that into page2, then use it in page2 to amend your page2 links.  

So in your repeater's code-behind you can do something like this:

Protected Sub rpt_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rpt.ItemDataBound
	Select Case e.Item.ItemType
		Case ListItemType.Item, ListItemType.AlternatingItem
			Dim MyHyperLink As HyperLink = CType(e.Item.FindControl("MyHyperLinkID"), HyperLink)
			MyHyperLink.NavigateUrl = "Page2.asp?Cust_Code=" & e.Item.DataItem("codevalue").ToString & "&senderID=" & MyHyperLink.ClientID
	End Select
End Sub

Open in new window


That will create a Hyperlink with a NavigateUrl of the actual link you are clicking on, with your codevalue also in the querystring.

Then on page2.aspx, in Page.Pre_Render you can read the querystring, and append it to any links that are on that page.  So say you have a HyperLink called Page2Link, you can do this:

Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
	If Request.QueryString("senderID") IsNot Nothing AndAlso Request.QueryString("senderID").ToString.Trim <> String.Empty Then
		Page2Link.NavigateUrl = Page2Link.NavigateUrl & "#" & Request.QueryString("senderID").ToString.Trim
	End If
End Sub

Open in new window


Pre_Render is the last Sub to run on a page, so it runs after all data has been loaded into the page.  So we find the hyperlink back to page1, and then add the ID of the link on page1, so when you navigate back, the page will use the technique from my original post to return to that exact spot.
0
 

Author Comment

by:Donna Kainer
ID: 36892743
The javascript BACK trick did not work. There is a syntax problem with the onclick="onClick="history.go(-1)" portion of the code. I tried changing it to onclick="onClick='history.go(-1)'" but that did not work.

I would really like to use your perferred method, but I am not certain what to do.

My Page1.asp Repeater hyperlink code right now is:  
<td>
    <asp:HyperLink runat="server" target="_blank" ID="Hyperlink1"
                            NavigateUrl='<%# "CustomerDetailForm.aspx?Cust_Code=" + DataBinder.Eval(Container.DataItem,"Cust_Code")%>'   
                            Text='<%#DataBinder.Eval(Container.DataItem, "Cust_Code")%>' 
                        />
</td>

Open in new window


How do I change it so that I build the hyperlink using the Protected Sub rpt_ItemDataBound you described above?
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 36892947
Just try the Js version first it's far easier! Try replacing NavigateUrl="#" with

NavigateUrl="javascript:history.go(-1)"
0
 

Accepted Solution

by:
Donna Kainer earned 0 total points
ID: 36980785
I have decided to leave Page1 open. I am not going to pursue this matter further.
0
 

Author Closing Comment

by:Donna Kainer
ID: 37010540
I am not going to pursue this matter any further.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

631 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