I’m trying to add a hyperlink inside of a label in an Intranet application. This application is only visible inside of our company, and I want to be able to allow the user to click on part of the page title to return to the root page. I tried this and it doesn’t work:
<td align="center" colspan="2">
<asp:Label ID="Label1" runat="server" Text="<a href=""/.."">Client Operations Daily Production Log</a> - Coaching Admin" Font-Size="XX-Large"></asp:Label>
<asp:Label ID="Label_Environment" runat="server" Font-Size="X-Large" Font-Bold="true" ForeColor="Red" Style="text-shadow:-1px 0 white, 0 1px white, 1px 0 white, 0 -1px white; padding-left:20px"></asp:Label>
</td>
2
Answers
I think the issue might be caused by the fact that you’d need to escape HTML-related markup inside the
Text
property of theasp:Label
.I would try to place the contents of that particular field inside the
asp:Label
like below:You can use code behind, and set the text of the label to this:
Note how when I hover over the label, the browser will show the target URL.
So, you can in most cases set the text of a label control to markup, and it will render that markup correctly, and this includes setting the text to a standard HTML hyperlink. In fact, you can even assign the label some JavaScript and it will run.