建立以文字為基礎的控制項,在行動裝置上顯示只供輸出的文字。標籤文字可以使用 Text 屬性 (Attribute),或以 <Label> 項目內容來指定。如果 Text 屬性 (Attribute) 可用兩種方式指定,則永遠以內部文字為優先。然而,如果 Text 屬性 (Attribute) 以程式設計方式設定,則內部文字會自動移除並以新設定的屬性 (Property) 為優先。
行動控制項語法
需要的屬性和具程式碼功能的項目以粗體樣式標註。
<mobile:Labelrunat="server"
id="id"
Font-Name="fontName"
Font-Size="{NotSet|Normal|Small|Large}"
Font-Bold="{NotSet|False|True}"
Font-Italic="{NotSet|False|True}"
ForeColor="foregroundColor"
BackColor="backgroundColor"
Alignment="{NotSet|Left|Center|Right}"
StyleReference="styleReference"
Text="Text"
Wrapping="{NotSet|Wrap|NoWrap}">
innerText
</mobile:Label>
內含項目規則
所有衍生自 TextControl 類別的具體類別的內含項目規則都相同。下列控制項可以包含 Label 控制項。
| 控制項 | 註解 |
|---|---|
| System.Web.UI.MobileControls.Form | 可以包含任何數目的 Label 控制項。 |
| System.Web.UI.MobileControls.Panel | 可以包含任何數目的 Label 控制項。 |
Label 控制項不可以包含任何其他控制項。
裝置樣板
無
裝置的特定行為
標籤所藉以呈現的樣式將因裝置而異,但標籤文字會出現在所有裝置上。標籤會以 HTML 和 WML 中的相同方式來呈現。
控制項會套用適當的樣式屬性 (Property) 而在其本身的一行中呈現標籤的文字。<br> 標記 (分行符號) 則跟隨在標籤後面。如果您在表單上將一個標籤加在另一個標籤之後,分行符號將造成標籤以直欄的方式呈現。
如需各種樣式屬性 (Attribute) 在不同裝置上如何解譯的詳細資訊,請參閱裝置的特定呈現文件。
範例
下列範例使用兩個標籤;每一個 Form 控制項上各一個。第一個標籤不會修改,因此不需要 ID 屬性 (Attribute)。第二個標籤的 ID 屬性 (Attribute) 值是 WelcomeMessage 而 Button_OnClick 事件處理常式會啟動其表單
<%@ Page Inherits=
"System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="vb" runat="server">
protected Sub Submit_Click(sender as Object, e as EventArgs)
WelcomeMessage.Text = "Welcome to my app, " + NameEdit.Text
ActiveForm = Form2
End Sub
</script>
<mobile:Form runat="server">
<mobile:Label runat="server">Enter your name</mobile:Label>
<mobile:TextBox runat="server" id="NameEdit" />
<mobile:Command runat="server" id="Submit" OnClick="Submit_Click">
OK
</mobile:Command>
</mobile:Form>
<mobile:Form runat="server" id="Form2">
<mobile:Label runat="server" id="WelcomeMessage" />
</mobile:Form>
[C#]
<%@ Page Inherits=
"System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="c#" runat="server">
protected void Submit_Click(Object sender, EventArgs e)
{
WelcomeMessage.Text = "Welcome to my app, " + NameEdit.Text;
ActiveForm = Form2;
}
</script>
<mobile:Form runat="server">
<mobile:Label runat="server">Enter your name</mobile:Label>
<mobile:TextBox runat="server" id="NameEdit" />
<mobile:Command runat="server" id="Submit" OnClick="Submit_Click">
OK
</mobile:Command>
</mobile:Form>
<mobile:Form runat="server" id="Form2">
<mobile:Label runat="server" id="WelcomeMessage" />
</mobile:Form>
請參閱
Label 類別 | Label 類別成員 | 控制項參考