tags:

views:

238

answers:

4

I have a master page, with a help link in the top menu. This link should contain the a dynamic bookmark from the current page, so that the user scrolls to the help for the page he is currently seeing.

<a href="help.aspx#[NameOfCurentPage]">Help</a>

How would you implement this?

+1  A: 

i haven't written a line of c# in over three months but you could hook up an event in the masterpage (OnLoad) and set the link from there. See what's in the ContentPlaceholder that's your main page and get it's type or name, then apply it to the link.

Kris
+1  A: 

I would use "Request.PhysicalPath" to get the physical path that was requested, then within your help HMTL you can denote the sections by what page they are about.

You might go as far as to use:

Path.GetFileName(Request.PhysicalPath).ToUpper()

to normalize the data. Using the PhysicalPath would allow you to have all logic in the master page; which would eliminate the need to write code in all content pages. Just my preference.

JPrescottSanders
Thats nice (tho i'd opt for ToLower()), but it doesn't give you access to the Page or it's properties etc. just a filename that's highly likely the same as the classname (would be plenty in 99.99% of all cases probably)
Kris
I don't think you need any access to the page's properties, what I like about his is you would write the logic in the master page, and then any pages that used that master would get this functionality. You wouldn't have to put logic in every content page.
JPrescottSanders
+3  A: 

Another thing you could do is reference the master page through the content page itself.

To make it easier on myself, I create a publicly accessible method in the master page itself:

Public Sub SetNavigationPage(ByVal LinkName As String)
   DirectCast(Me.FindControl(MenuName), HyperLink).NavigateUrl = "help.aspx#" & LinkName
End Sub

Then in the content page, I get a reference to the master page through the following...

Dim myMaster As MasterPageClass = DirectCast(Me.Master, MasterPageClass)
myMaster.SetNavigationPage("CurrentPage")
Dillie-O
My only issue with this solution is it would require you to put boiler plate code in every content page. I would perfer a solution that could be written entirely in the master page.
JPrescottSanders
Nice... while i agree with JPrescottSanders that this might require a lot code, you just saved my day on another task. 1 point for that ;-)
Thomas Jespersen
+1  A: 

Put

<a href="help.aspx#<%= Path.GetFileName(this.Page.Request.FilePath) %>">Help</a>

into the MasterPage, and then anchors on the help page in the format of:

<a name="page1.aspx" />Blah, blah
<a name="page2.aspx" />Blah, blah

If you repeat page names in subfolders, eg., Sub1/page1.aspx and Sub2/page1.aspx - you'll have to be slightly more clever.

Mark Brackett