Form Control

As a container for any number of controls, the Form control also represents the outermost grouping of controls within a MobilePage object. Because a form usually contains multiple controls, you can think of it as a separately addressable set of controls that you can browse to from within the application.

When you have multiple controls on an individual form, the ASP.NET separates these controls into multiple units for the appropriate target device. However, because a form is considered a separate unit of discourse (a separately addressable set of controls), ASP.NET never combines multiple forms on a single screen.

Mobile Controls Syntax

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

<mobile:Form
   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"
   Wrapping="{NotSet|Wrap|NoWrap}"

   Action="url"
   Method="{Post|Get}"
   OnActivate="activateHandler"
   OnDeactivate="deactivateHandler"
   OnPaginate=changeHandler"
   Paginate="{True|False}"
   Title="formTitle">
Place child controls here. (optional)
</mobile:Form>

Containment Rules

The following controls can contain a Form control.

Control Comments
System.Web.UI.MobileControls.MobilePage Must contain one or more Form controls.

A Form control can contain the following controls.

Control Comments
All members of System.Web.UI.MobileControls, except MobilePage, Form, and StyleSheet objects. Forms can contain any other ASP.NET mobile control, except other forms or style sheets.

Forms must contain one or more of the controls described in the Control column.

Device Templates

For information about how to specify the following templates, see the <DeviceSpecific> or <Choice> element.

Template Description
Header The header template is rendered at the beginning of the form. In paginated mode, the header is rendered on each page.
Footer The footer template is rendered at the end of the form. In paginated mode, the footer is rendered on each page.
Script The script template is rendered at the top of the form. If the form is paginated into several screens, each screen contains the script template. The code within the script template is added directly after the opening <head> tag on HTML-based devices, and directly after the opening <card> tag on WML-based devices.

The header and footer templates can be part of a device-independent template set. If the template set is device independent, the templates must contain mobile controls.

Device-Specific Behavior

If style properties are set on a Form control that cascades to individual controls, any device-specific behavior applicable to the individual controls will be applied to those style properties.

For devices that support using TAB between controls, tab order is defined by either the order that the controls appear on the page, or when controls are added dynamically, the order that they are added to the page.

Device language Description of behavior
HTML If a form has a Title property defined, the title is written out in a <title> tag in the <head> section of the document.

If templates are rendered, they are written out in order within the <body> tag.

The following code shows a basic outline of an HTML page.

<head>
  <title>title</title>
</head>
<body>
Add header template here.
  Add form contents here.
Add footer template contents here.
</body>

You can use the preceding code for a form that fits entirely on a single page or a form that is not undergoing pagination.

WML If a form has a Title property defined, the title is written out as the Title attribute of a <card> tag for the form. (In rare cases, this has unexpected results on some devices and is not written out within a <card> tag.)

If templates are rendered, they are written out in order within a <p> tag inside a WML card.

The following code shows the basic outline of a WML page.

<card title="title">
<p>
header template
content template or form contents
footer template
</p>
</card>

Example

The following example creates a form with two labels.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<mobile:Form runat="server">
  <mobile:Label runat="server">Aardvark</mobile:Label>
  <mobile:Label runat="server">Bear</mobile:Label>
</mobile:Form>

See Also

Form Class | Form Class Members | Control Reference