Jaa


Forms

An HTML form is a section of a Web page containing content, markup tags, controls (check boxes, radio buttons, menus, and so on), and labels for those controls. In ASP.NET mobile Web pages, forms extend the Microsoft ASP.NET technology across diverse devices. For a detailed list of basic capabilities, see ASP.NET Web Pages Overview .

In an ASP.NET mobile Web page, a form provides the interface between the browser capabilities of a page object and the code that renders that page. The form is a container for controls that encapsulate page logic into reusable components. The form also enables separation of code and content on a page.

Form Activation

Every ASP.NET mobile Web 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 page activates a different form.

  • Using a Link control that links to another form activates that form when the link is clicked.

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

You can place any number of controls in an individual form. However, for usability, it is advisable to minimize the number of controls you add to a form.

ASP.NET organizes these controls into multiple units, such as a screen, as appropriate for the target device. The Form control then 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 personal information by accessing that form.

Note

You cannot navigate to arbitrary forms in other pages, or through an external URL. In other words, no external URL can 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 that page.

To determine whether you want to create a new form or add more controls to an existing form, determine the functionality you require. Create a new form if you need a separately addressable set of controls. This is especially useful when the user is moving to a different part of the application. Otherwise, you can add controls to an existing form. Because individual Form controls are considered separate units of interaction, ASP.NET never combines multiple forms into a single display, even if there is screen area to do so.

Creating Pages versus Forms

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

A page provides 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. In contrast, state management between pages 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. In contrast, 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. In addition, it is best to place less-frequently used forms in separate pages.

See Also

Concepts

Pages

Panels

Pagination

Styles

Other Resources

Design and Rendering Concepts for ASP.NET Mobile Controls

Application Developer's Guide