如何在母版页中创建链接,其中包含当前页面的动态信息?

时间:2021-02-27 07:15:59

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?

你会如何实现这个?

4 个解决方案

#1


3  

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")

#2


1  

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.

我会使用“Request.PhysicalPath”来获取所请求的物理路径,然后在您的帮助HMTL中,您可以通过它们所关注的页面来表示这些部分。

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.

规范化数据。使用PhysicalPath将允许您在母版页中拥有所有逻辑;这将消除在所有内容页面中编写代码的需要。只是我的偏好。

#3


1  

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.

我在三个多月内没有写过一行c#但你可以在主页(OnLoad)中挂钩一个事件并从那里设置链接。查看ContentPlaceholder中您的主页面中的内容并获取其类型或名称,然后将其应用于链接。

#4


1  

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:

进入MasterPage,然后在帮助页面上锚定格式:

<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.

如果你在子文件夹中重复页面名称,例如,Sub1 / page1.aspx和Sub2 / page1.aspx - 你必须要稍微聪明一些。

#1


3  

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")

#2


1  

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.

我会使用“Request.PhysicalPath”来获取所请求的物理路径,然后在您的帮助HMTL中,您可以通过它们所关注的页面来表示这些部分。

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.

规范化数据。使用PhysicalPath将允许您在母版页中拥有所有逻辑;这将消除在所有内容页面中编写代码的需要。只是我的偏好。

#3


1  

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.

我在三个多月内没有写过一行c#但你可以在主页(OnLoad)中挂钩一个事件并从那里设置链接。查看ContentPlaceholder中您的主页面中的内容并获取其类型或名称,然后将其应用于链接。

#4


1  

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:

进入MasterPage,然后在帮助页面上锚定格式:

<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.

如果你在子文件夹中重复页面名称,例如,Sub1 / page1.aspx和Sub2 / page1.aspx - 你必须要稍微聪明一些。