添加链接到一个标签ASP.NET(VB) [英] Adding link to a label ASP.NET (VB)
问题描述
我有一个标签
,我想给它添加一个链接。
I have a label
and I want to add to it a link.
我想用的JavaScript
这样的:
MyLabel.Attributes.Add("`onclick`", "javascript:`SOME_CODE`")
我必须加入( SOME_ code
)将用户重定向到另一个链接。
What must I add in (SOME_CODE
) to redirect the user to another link.
感谢。
推荐答案
你试过:了window.location =http://google.com
?
是要使用JavaScript这个什么特别的原因,而不是仅仅的超级链接控制?
Have you tried: window.location = 'http://google.com'
?
Are the any particular reason you want to use Javascript for this, and not just the HyperLink Control?
更新:
您可以使用一个正常的一个标签< A HREF =http://google.com>链接< / A>
或使用ASP .NET HyperLink控件:
You can either use a normal a-tag <a href="http://google.com">link</a>
or use the ASP.Net HyperLink control:
这是标记:
<asp:HyperLink ID="MyHyperLinkControl" NavigateUrl="http://google.com" runat="server" />
这是,如果你想将它从code-后面加上:
This is if you want to add it from the code-behind:
HyperLink link = new HyperLink();
link.NavigateUrl = "http://google.com";
parentControl.Controls.Add(link);
其中, parentControl
,是你要添加的容器,例如在一个表或面板的单元格。
Where parentControl
, is the container you want to add it to, for instance a cell in a table or a panel.
请参阅这里有关如何将控件添加到面板的更多信息
See here for more information on how to add a control to a panel
这篇关于添加链接到一个标签ASP.NET(VB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!