一个超链接位于多个不同位置
我想在我的网站上的许多位置实现超链接,但是我只想将其定义一次而不是多次。实现这一目标的最佳方法是什么?
我开始将其列在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建继承自 HyperLink 的自定义控件。此方法不需要在各个页面上使用代码隐藏,但您需要创建一个新类并修改您的 web.config 文件。根据需要更改命名空间。
SpecialLink.vb
web.config(将其添加到 system.web 节点)
这允许您在整个网站的任何页面/母版页/用户控件上使用此控件
在您的页面上使用它
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
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
Using it on your page
在每个页面上您想要的位置放置一个
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 theNavigateUrl
in the markup.[Sorry, that's C# code]