ASP.NET - Label

ASP.NET - Label 首页 / ASP.Net MVC入门教程 / ASP.NET - Label

此控件用于在Web窗体上显示文本信息。它主要用于为其他控件(如:TextBox)创建标题。

要创建Label标签,无涯教程可以编写代码,也可以使用Visual Studio 2017的拖放功能。

这是服务器端控件,asp提供自己的标签来创建标签。下面给出了示例。

无涯教程网

<asp:LabelID="Label1" runat="server" Text="Label" ></asp:Label>

此控件具有自己的属性,如下表所示。

Property Description
AccessKey 它用于为标签设置键盘快捷键。
TabIndex 控件的选项卡顺序。
BackColor 它用于设置标签的背景颜色。
BorderColor 它用于设置标签的边框颜色。
BorderWidth 它用于设置标签边框的宽度。
Font 它用于为标签文本设置字体。
ForeColor 它用于设置标签文本的颜色。
Text 它用于设置要为标签显示的文本。
ToolTip 它显示鼠标在标签上时显示文本。
Visible 在表格上设置控制的可见性。
Height 它用于设置控件的高度。
Width 它用于设置控件的宽度。

示例

//WebControls.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs" 
Inherits="WebFormsControlls.WebControls" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            margin-left: 0px;
        }
        .auto-style3 {
            width: 121px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
           <h4>Provide the Following Details:</h4>
            <table class="auto-style1">
                <tr>
                    <td class="auto-style3">
                        <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style2"></asp:TextBox></td>
                </tr>
                <tr>
                    <td class="auto-style3">
                        <asp:Label ID="Label2" runat="server" Text="Upload a File"></asp:Label></td>
                    <td>
                        <asp:FileUpload ID="FileUpload1" runat="server" /></td>
                </tr>
            </table>        
        </div>
    </form>
</body>
</html>

这是标签控件的属性窗口。

ASP Label 1

在这里,无涯教程使用了带有两个不同控件的Label控件。它会产生以下输出。

ASP Label 2

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

朱赟的技术管理课 -〔朱赟〕

玩转Spring全家桶 -〔丁雪丰〕

Linux实战技能100讲 -〔尹会生〕

说透敏捷 -〔宋宁〕

NLP实战高手课 -〔王然〕

操作系统实战45讲 -〔彭东〕

如何讲好一堂课 -〔薛雨〕

Serverless进阶实战课 -〔静远〕

云原生架构与GitOps实战 -〔王炜〕

好记忆不如烂笔头。留下您的足迹吧 :)