admin管理员组文章数量:1391850
I have a label
and I want to add to it a link.
I want to use javascript
like :
MyLabel.Attributes.Add("`onclick`", "javascript:`SOME_CODE`")
What must I add in (SOME_CODE
) to redirect the user to another link.
Thanks.
I have a label
and I want to add to it a link.
I want to use javascript
like :
MyLabel.Attributes.Add("`onclick`", "javascript:`SOME_CODE`")
What must I add in (SOME_CODE
) to redirect the user to another link.
Thanks.
Share Improve this question asked Jun 16, 2010 at 22:09 FarmerFarmer 11k40 gold badges123 silver badges175 bronze badges 1- Have the replies answered your question? – Jesper Fyhr Knudsen Commented Jun 17, 2010 at 16:13
4 Answers
Reset to default 3Have you tried: window.location = 'http://google.'
?
Are the any particular reason you want to use Javascript for this, and not just the HyperLink Control?
Update:
You can either use a normal a-tag <a href="http://google.">link</a>
or use the ASP.Net HyperLink control:
This is the markup:
<asp:HyperLink ID="MyHyperLinkControl" NavigateUrl="http://google." runat="server" />
This is if you want to add it from the code-behind:
HyperLink link = new HyperLink();
link.NavigateUrl = "http://google.";
parentControl.Controls.Add(link);
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
Just use a plain anchor tag (<a >
), but put the label inside the anchor (the reverse is not strictly valid html). If you don't want it to show up as a link every time, you can acplish that by omitting the href
attribute. This is easy to do with a normal <asp:HyperLink>
server control like so:
<asp:HyperLink id="..." runat="server"><asp:Label ... ></asp:Label></asp:HyperLink>
Now, the href attribute will only render if you actually set the NavigateUrl property in your code. You might also find that using an <asp:HyperLink>
pletely replaces the need for the label.
<a href="http://google." >Go to Google</a>
If this has anything to do with your previous question, use a Hyperlink
control instead of a Label
:
Dim Hyperlink1 As New Hyperlink
Hyperlink1.Text = "XYZ"
Hyperlink1.NavigateUrl = "http://www.google."
Dim Literal1 As New Literal
Literal1.Text = "<br />"
' Add the control to the placeholder
PlaceHolder1.Controls.Add(Hyperlink1)
PlaceHolder1.Controls.Add(Literal1)
本文标签: javascriptAdding link to a label ASPNET (VB)Stack Overflow
版权声明:本文标题:javascript - Adding link to a label ASP.NET (VB) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744769604a2624257.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论