How to display a link in a Label in asp.net

asp.net example - label link
Label is an asp.net web server control. Label control allow us to display text on web page. Unlike static text, we can customize the displayed text by using label control's Text property. Label server control can render some HTML tags such as <b>, <a> etc.

So we can display an active link on web page using Label control. This help us to show link inside static text. We just need to place a well formatted HTML anchor tag in label control's Text property value.

The following asp.net c# example code demonstrate us how can we display an active link in a Label control in an asp.net application.
label-link.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
    
<!DOCTYPE html>
      
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Label1.Text = "asp.net c# examples blog....<br />";
        Label1.Text += "<a href='http://asp-net-example.blogspot.com'>asp.net c# examples<a/>";
    }  
</script>      
      
<html xmlns="http://www.w3.org/1999/xhtml">      
<head id="Head1" runat="server">      
    <title>asp.net example - label link</title>
</head>      
<body>      
    <form id="form1" runat="server">      
    <div>      
        <h2 style="color:MidnightBlue; font-style:italic;">      
            asp.net example - label link
        </h2>      
        <hr width="550" align="left" color="Gainsboro" />      
        <asp:Label       
            ID="Label1"       
            runat="server"      
            Text="sample label to test link inside label control."
            Font-Size="X-Large"
            >      
        </asp:Label>      
        <br /><br /><br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="label link"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>      
    </form>      
</body>      
</html>
More asp.net examples