Share via


Custom Attributes for Mobile Controls

All ASP.NET mobile controls allow you to set custom control attributes using the IAttributeAccessor interface of ASP.NET Web pages. This interface provides the methods GetAttribute and SetAttribute. Additionally, the MobileControl class exposes a collection named CustomAttributes.

Custom attributes can be used to specify additional attributes about a control and can be used in a device-specific adapter to adjust the control's behavior or rendering.

By default, the ability to set custom attributes on a control is disabled. There are two ways to enable custom attributes:

  • By setting an attribute of the <mobileControls> section in the Web.config file, as shown in the following code example:

    <configuration>
      <system.web>
            ...
          <mobileControls allowCustomAttributes="True" />
          ...
      </system.web>
    </configuration>
    

    This setting affects the default of all pages in the application.

  • By setting the AllowCustomAttributes property of the MobilePage class to true. This setting affects all controls on the page.

The wmlFormat attribute for the TextBox control is sent to WML devices as the Format attribute of the WML <input> element. This is a custom attribute and is distinct from the first-class attributes of the control. However, before custom attributes will work, you must enable them. For a full listing of valid formats, see the WML specification, available through the Wireless Application Protocol Forum (WAP) at http://www.wapforum.org.

The wmlFormat attribute overrides the Numeric property for the TextBox control. For example, if the wmlFormat attribute is set to "NNN," the <input> element is limited to three numeric characters.

Note

With custom attributes turned on, typographic errors in property names can be mistaken for custom attributes. For example, if you incorrectly specify the Text property of a control as "Txet," the parser saves it as a custom attribute named "Txet" instead of raising an exception. As a precaution, custom attributes are disallowed by default.

See Also

Reference

HasCapability

MobileControl

Concepts

Configuring a Web Application for Multiple Devices

Device Filtering Recommendations

Device Evaluation Methods

Extended Browser Capabilities

Other Resources

Creating Custom Mobile Controls