一个超链接位于多个不同位置

发布于 2024-09-18 01:40:07 字数 255 浏览 4 评论 0原文

我想在我的网站上的许多位置实现超链接,但是我只想将其定义一次而不是多次。实现这一目标的最佳方法是什么?

我开始将其列在 web.config 的节点中,但我只能将其作为文字列出,并且未能成功地将其最终作为超链接。

我对母版页了解不多,但在我看来,它们并不是此任务的答案,因为它们不允许该超链接位于某些页面上,而不是其他页面上,并且在某些页面上的位置与其他页面上的位置不同。

请帮忙! :)

我正在 ASP.net VB.net 工作

I'd like to implement a hyperlink in many locations on my website, however I just want to have it defined once not several times over. What is the best way to achieve this?

I started down the road of listing it in the node of web.config but I was only able to get that to list as a literal and wasn't successful in having it end up as a hyperlink.

I don't know much about master pages, but what I do know about them seems to me that they aren't the answer for this task because they wouldn't allow for that hyperlink to be located on some pages and not others and in different locations on some pages than others.

Help please! :)

I'm working in ASP.net VB.net

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾挽 2024-09-25 01:40:16

您可以创建继承自 HyperLink 的自定义控件。此方法不需要在各个页面上使用代码隐藏,但您需要创建一个新类并修改您的 web.config 文件。根据需要更改命名空间。

SpecialLink.vb

Namespace YourWebSite.Controls
 Public Class SpecialLink
  Inherits HyperLink

  Public Sub New()
   NavigateUrl = "~/SpecialLinkUri.aspx"
   Text = "Special Link Text"
  End Sub
 End Class
End Namespace

web.config(将其添加到 system.web 节点)
这允许您在整个网站的任何页面/母版页/用户控件上使用此控件

<pages>
  <controls>
   <add namespace="YourWebSite.Controls" tagPrefix="YourWebSite"/>
  </controls>
</pages>

在您的页面上使用它

<p>This is some text, here's the link: <YourWebSite:SpecialLink></YourWebSite:SpecialLink></p>
<p>This is some text, <YourWebSite:SpecialLink>here's the link</YourWebSite:SpecialLink>.</p>

You can create a custom control that inherits from HyperLink. This method will not require to use code-behind on individual pages but you will need to create a new class and modify your web.config file. Alter the namespaces as needed.

SpecialLink.vb

Namespace YourWebSite.Controls
 Public Class SpecialLink
  Inherits HyperLink

  Public Sub New()
   NavigateUrl = "~/SpecialLinkUri.aspx"
   Text = "Special Link Text"
  End Sub
 End Class
End Namespace

web.config (add this to the system.web node)
This allows you to use this control on any page/master page/user control throughout your site

<pages>
  <controls>
   <add namespace="YourWebSite.Controls" tagPrefix="YourWebSite"/>
  </controls>
</pages>

Using it on your page

<p>This is some text, here's the link: <YourWebSite:SpecialLink></YourWebSite:SpecialLink></p>
<p>This is some text, <YourWebSite:SpecialLink>here's the link</YourWebSite:SpecialLink>.</p>
唠甜嗑 2024-09-25 01:40:14

在每个页面上您想要的位置放置一个 HyperLink 控件。

例如 Login

然后在代码中的超链接上设置 NavigateUrl 属性- 后面,例如 this.LogInLink.NavigateUrl = Global.MySpecialUrl; 或使用 <%=Global.MySpecialUrl%> 表示法从代码中引用您想要的值在标记中的 NavigateUrl 中。

[抱歉,这是 C# 代码]

Put a HyperLink control on each page where you want it.

e.g. <asp:HyperLink runat="server" id="LogInLink">Login</asp:HyperLink>

Then either set the NavigateUrl property on the hyperlink in code-behind, e.g. this.LogInLink.NavigateUrl = Global.MySpecialUrl; or use <%=Global.MySpecialUrl%> notation to reference the value you want from your code in the NavigateUrl in the markup.

[Sorry, that's C# code]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文