ASP.NET中Label控件用法详解


Label 控件提供了一种在 ASP.NET 网页中以编程方式设置文本的方法。当希望在运行时更改网页中的文本(比如响应按钮单击)时,通常可以使用 Label 控件。

一、属性

Label控件的常用属性及说明如表1所示。

表1 Label控件常用属性及说明

属性 说明
ID 控件的ID名称
Text 控件显示的文本
Width 控件的宽度
Visible 控件是否可见
CssClass 控件呈现的样式
BackColor 控件的背景颜色
Enabled 控件是否可用

下面详细介绍Label控件的一些重要属性。

1.ID属性

ID属性用来惟一标识Label控件,程序开发人员在编程过程中可以利用ID属性调用该控件的属性、方法和事件。可通过属性对话框对ID属性进行设置,如图1所示。

图1  Label控件属性设置

注意:
(1)Label控件的属性设置也可以通过HTML代码实现,实现代码如下:

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Label控件示例</title>
</head>
 
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="labTest" runat="server" BackColor="Green" BorderColor="Blue" Font-Bold="True"
            Font-Names="宋体" Font-Size="24pt" ForeColor="White" Height="20px" OnLoad="labTest_Load"
            Text="Label示例" Width="167px" BorderWidth="2px"></asp:Label></div>
    </form>
</body>
</html>


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3