This documentation is archived and is not being maintained.

Label Control

.NET Framework 1.1

Creates a text-based control that displays output-only text on a mobile device. The text of a label can be specified either by using the Text attribute, or as the content of the <Label> element. If the Text attribute is specified in both ways, the inner text always takes precedence. If, however, the Text attribute is programmatically set, the inner text is automatically removed, and the newly set property takes precedence.

Mobile Controls Syntax

Required properties, defaults, and code-featured elements are noted in bold type.

<mobile:Label
   runat="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>

Containment Rules

The containment rules for all concrete classes derived from of the TextControl class are the same. The following controls can contain a Label control.

Control Comments
System.Web.UI.MobileControls.Form Can contain any number of Label controls.
System.Web.UI.MobileControls.Panel Can contain any number of Label controls.

The Label control cannot contain any other controls.

Device Templates

None.

Device-Specific Behavior

The style with which a label is rendered will differ based on device, but the label text will appear on all devices. The label is rendered the same way in HTML and WML.

The control renders the text of the label on its own line with the appropriate style attributes applied. A <br> tag (line break) follows the label. If you add one label after another on a form, the line breaks will cause the labels to be rendered in a vertical column.

For more information about how the different style attributes are interpreted on different devices, see the Device-Specific Rendering documentation.

Example

The following example uses two labels, one on each Form control. The first label is not modified, and thus does not require an ID attribute. The value of the second label has the ID attribute of WelcomeMessage and the Button_OnClick event handler activates its form

<%@ 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>

See Also

Label Class | Label Class Members | Control Reference

Show: