Share via


Pages

Every ASP.NET mobile Web Forms page inherits from the MobilePage class. Browsers initially display the first form on a page.

The inheritance chain of a mobile Web Forms page depends on how the page is written. If a mobile Web Forms page is totally self-contained, it inherits directly from the MobilePage class. However, in code-behind scenarios, the page might inherit from a developer-supplied class. In this case, the specified class itself inherits from the MobilePage class.

Note   The ASP.NET mobile designer uses a code-behind model for pages. A mobile Web Forms page authored in Visual Studio .NET always inherits from an automatically generated code-behind class, which itself inherits from a MobilePage.

When constructing an application, it is recommended that you create a new mobile Web Forms page only when you want to:

  • Present a different URL to the user
  • Increase performance

Every ASP.NET mobile Web Forms page must contain the following @ Page directive.

<%@ Page Inherits = 
        "System.Web.UI.MobileControls.MobilePage" Language="C#" %>

Note   When you create a mobile Web Forms page in the mobile designer, the designer automatically adds the @Page directive for you.

The directive instructs the Web Forms page compiler to use the MobilePage class as the base class for the page. The Inherits attribute of the @ Page directive is required. If the page inherits directly from the MobilePage class, the Inherits attribute must be set to the System.Web.UI.MobileControls.MobilePage namespace. Alternatively, if the page inherits from a code-behind class, you must specify the name of that class instead. The Language attribute is optional, and can be set to the language used on the page (standard usage).

Note   If you are writing an application that targets .NET Framework version 1.0, you will need to add the @Register TagPrefix value to allow your application to run.

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

The @Register directive registers the namespace that the ASP.NET mobile controls use with the mobile prefix. This allows you to declare mobile controls on the page by using the mobile prefix in a tag, such as in the tag <mobile:Label>. Although, theoretically, you can use any prefix, the mobile prefix is strongly recommended for forward compatibility.

Inheritance

The inheritance chain of a mobile Web Forms page depends on how the page is written. If a mobile Web Forms page is completely self-contained, it should inherit directly from the MobilePage class. However, in code-behind scenarios, the page can inherit from a developer-supplied class. In this case, the specified class should itself inherit from the MobilePage class.

Note   The Microsoft Visual Studio .NET Web Forms designer always uses a code-behind model for pages. A mobile Web Forms page authored in Visual Studio .NET always inherits from an automatically generated code-behind class, which itself inherits from the MobilePage class.

See also

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