How to trim text with ellipsis in a Label in asp.net

asp.net example - label ellipsis
label-ellipsis.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
    
<!DOCTYPE html>
      
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Label1.CssClass = "LabelEllipsisStyle";
    }  
</script>      
      
<html xmlns="http://www.w3.org/1999/xhtml">      
<head id="Head1" runat="server">      
    <style type="text/css">
        .LabelEllipsisStyle {
            text-overflow:ellipsis;
            white-space:nowrap;
            display:block;
            overflow:hidden;
        }
    </style>      
    <title>asp.net example - label ellipsis</title>
</head>      
<body>      
    <form id="form1" runat="server">      
    <div>      
        <h2 style="color:MidnightBlue; font-style:italic;">      
            asp.net example - label ellipsis
        </h2>      
        <hr width="550" align="left" color="Gainsboro" />      
        <asp:Label       
            ID="Label1"       
            runat="server"      
            Text="sample label to test label ellipsis."
            BorderColor="Red"
            BorderWidth="1"
            Font-Size="X-Large"
            Width="250"
            ToolTip="sample label to test label ellipsis."
            >      
        </asp:Label>      
        <br /><br /><br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="label ellipsis"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>      
    </form>      
</body>      
</html>
More asp.net examples