An HTML form is a section of a Web page containing normal content, markup tags, special elements called controls (check boxes, radio buttons, menus, and so on), and labels on those controls. In ASP.NET mobile controls, forms extend the Microsoft ASP.NET technology across diverse devices. See Introduction to Web Forms for a detailed list of basic capabilities. Basically, a form in an ASP.NET mobile Web application provides the interface between the browser capabilities of a page object and the code that renders that page. The form is a container that allows for a rich set of controls that cleanly encapsulate page logic into reusable components, and it allows for separation of code and content on a page. Just as in XML, you separate code from data or content; in ASP.NET mobile controls, a form is a container that separates the content.

Form Activation

Every ASP.NET mobile Web Forms page has one form that is currently active. A form is activated in the following ways:

  • Accessing a page for the first time activates the first form on the page, which raises the Activate event.
  • Setting the ActiveForm property of the mobile Web Forms page on subsequent postbacks activates another form.
  • Using a Link control that links to another form activates a form on subsequent postbacks.

The latter two actions first raise the Deactivate event of the previously active form, and then raise the Activate event of the current form.

There is no reliable way to gauge when a user leaves the current page; thus, the last visited form is never deactivated, and its Deactivate event is never raised.

Organizing Content in Forms

Any number of controls can be placed in an individual form. However, for usability, it is advisable to minimize the number of controls you add to a form. Too many controls can cause problems.

ASP.NET organizes these controls into multiple units, such as a screen, for the appropriate target device. From the developer's perspective, a Form control represents an individually addressable set of controls that you can navigate to, from within the page. For example, if you have two forms on a page, and one form contains employee personal information and the other contains the employee's employment history, you can reference the bulk of personal information by accessing the form.

Note   You cannot navigate to arbitrary forms in other pages, or through an external URL. In other words, no externally meaningful URLs take you to a given form within a page. When you browse to a page, the first form automatically becomes active. To change to another form, you must set the ActiveForm property of the page.

Design Phase Criteria

As a mobile Web applications developer, you are also a designer. What criteria can you use to determine whether you want to create a new form or add more controls to an existing form? The answer is based in functionality. Create a new form if you need a separately addressable set of controls. You especially want to do this if you are transitioning the user to a different phase of the application. Otherwise, you can add controls to an existing form.

Distinguishing Pages and Forms

When you create an instance of a page, instances of all forms on that page are created, regardless of the current active form. An overhead is, therefore, dependent on the number of forms on a page.

A page provides rich view-state management over multiple requests. Because instances of all forms on a page are created, any control on any form is addressable from the page. From one page to another, state management is much more limited, and you must write custom code to provide additional features.

Only the first form of a page is addressable from an external page. Each page has its own URL. Thus, the more closely related two forms in an application are, the more sensible it is to place them on the same page. Also, it is best to place less frequently used forms or branches of the application in separate pages.

When to Create a New Form Control

Create a new Form control if you need a separately addressable set of controls. For example, if you want to transition the user to a different phase of the application, you add another Form control. Otherwise, you add more controls to an existing Form control.

Because individual Form controls are considered separate units of interaction, ASP.NET never combines them into a single display, even if there is screen area to do so.

See Also

Designing and Rendering Concepts for Mobile Controls | Application Developer's Guide | Pages | Panels | Pagination | Styles