Custom Attributes

All ASP.NET mobile controls allow the developer to set custom control attributes by using the IAttributeAccessor Interface of Web Forms. This interface provides the methods IAttributeAccessor.GetAttribute and IAttributeAccessor.SetAttribute; additionally, the MobileControl class exposes a dictionary called 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 to the <mobileControls> section in Web.config, as shown in the following code example.

            <mobileControls allowCustomAttributes="True" />

    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 property 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

Note   The wmlFormat attribute overrides the Numeric property for the Textbox control. For example, if the wmlFormat attribute was set to "NNN," the <input> element would be limited to three numeric characters.

Caution   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 called "Txet" instead of raising an exception. As a precaution, custom attributes are set to off by default.

See Also

Configuring a Web Application for Multiple Devices | Device Filtering Recommendations | HasCapability Method | Device Evaluation Methods | Extended Browser Capabilities | MobileControl Class