Aracılığıyla paylaş


Working with Environment Tools 

There are some restrictions on how you can manipulate mobile controls. For example, errors can occur if you mistakenly drop a control in the wrong place or misspell a word in an @ Register directive.

Control Restrictions

Visual Studio displays an error message when you misplace a control on the page in Design view. Use the following guidelines to prevent errors when using the designer:

  • Use mobile Web controls only on ASP.NET mobile Web pages.

  • Place all controls except Form and StyleSheet controls into containers or mobile user controls.

  • Follow the containment rules for the control. For more information, see the "Containment Rules" section of Mobile Controls Reference.

  • Ensure that the @ Register directive is spelled correctly.

Do not:

  • Place an ASP.NET mobile Web control onto a page that is not an ASP.NET mobile Web page.

  • Place a Web server control or HTML server control anywhere on a mobile Web page other than in a Form or template.

  • Exceed the number of controls allowed in a page or container. For example, multiple StyleSheet controls are not allowed on the same page.

  • Delete the @ Register directive from a mobile Web page.

    NoteNote

    If a page was created on one version of the .NET Framework but is running on a later version, you might need to add an @ Register directive to the page. See below for an example of the required @ Register directive.

The following sections give more specific information about possible error conditions.

Page Violations

An exception is raised when a page that contains mobile Web controls is loaded in Visual Studio, but the page is not of type MobilePage. In that case, the following error message is displayed:

This control only works in pages of type MobilePage.

An exception is also raised when a mobile Web page containing mobile Web controls is loaded into a version of the Visual Studio earlier than 1.1 and the @ Register directive is missing or incorrect. In that case, the following error message occurs:

ASP.NET Project Page Violation

Move your mouse over a control to view a tooltip that provides more error information.

NoteNote

If you are writing an application that targets version 1.0 of the .NET Framework, you must add the following TagPrefix attribute to the @ Register directive:

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

Containment Violations

If an ASP.NET Web server control is placed on a mobile Web page outside a template, the following error message occurs:

This page can only support nonmobile controls in templates. Please delete this control or move it into a template.

To correct the problem, delete or move the control.

The following actions also cause containment violations:

  • A Form control is not placed at the top level of the page.

  • A Panel control is placed outside a Form control or template.

  • A DeviceSpecific control is placed outside a Form control or a Panel control.

  • A StyleSheet control is not placed at the top level of the page.

  • Any other mobile Web control is placed outside a Form control, a Panel control, or a template.

If more than one StyleSheet control is added to a page, the second StyleSheet control is disabled and renders with an error message. If the first StyleSheet control is deleted, the remaining StyleSheet control becomes the active one.

If more than one DeviceSpecific control is added to a container control, the second one is disabled and renders with an error message. If the first instance is deleted, the remaining control becomes the active one.

See Also

Concepts

Using Stylesheets

Other Resources

Customizing ASP.NET Mobile Web Controls for Specific Devices