Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
218 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
  • 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 111

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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 111

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

877 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