skip to Main Content

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


  1. I think the issue might be caused by the fact that you’d need to escape HTML-related markup inside the Text property of the asp:Label.

    I would try to place the contents of that particular field inside the asp:Label like below:

    <td align="center" colspan="2">
       <asp:Label ID="Label1" runat="server" Font-Size="XX-Large">
          <a href=""/.."">Client Operations Daily Production Log</a> - Coaching Admin
       </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>
    
    Login or Signup to reply.
  2. You can use code behind, and set the text of the label to this:

            string sRootURL = ResolveClientUrl("~/");
    
            string sAREF = $@"<a href='{sRootURL}'>Jump to Root</a>";
    
            Label1.Text = sAREF;
    

    Note how when I hover over the label, the browser will show the target URL.

    enter image description here

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search