SUMMARY
This step-by-step article describes how to create a right softkey for Wireless Markup Language (WML) mobile devices.
back to the top
Description of the Technique
Softkeys are buttons on mobile devices that allow users to execute functionality in a mobile Web Form. These buttons are typically located under the screen of the mobile device. The buttons correspond to a value that appears above the button on the screen. This value identifies the action that is taken when the user presses the softkey.
Not all mobile devices have softkeys. Some mobile devices have one softkey, and some mobile devices have two softkeys. When a device has two buttons, the button on the right is called the right softkey.
Microsoft Mobile Internet Toolkit (MMIT) provides a
SoftkeyLabel property on some of the mobile controls. In most cases, this property sets the value of the left softkey. Mobile controls do not include a property to set the value of the right softkey.
Because mobile controls do not include a property to set the value of the right softkey, you can use the
ScriptTemplate template to insert the WML code that creates the softkey. When you use
ScriptTemplate, you must make sure that the code in
ScriptTemplate is only rendered to mobile devices that support two softkeys. To do this, you can use the
<deviceFilters> section of the Web.config file to render the code only to supporting devices.
back to the top
Steps to Create a Device Filter
The
<deviceFilters> section is available in the Web.config file of your mobile Web application. The device filter uses the
MobileCapabilities class to determine whether a device can support a particular feature.
To filter by device in the
<deviceFilters> section, follow these steps:
- Open the Web.config file that is located the root of your mobile Web application.
- Add the following code to the <system.web> section of your Web.config file:
<deviceFilters>
<filter name="supports2SoftKeys" compare="NumberOfSoftkeys" argument="2"/>
</deviceFilters>
- Save and close the Web.config file.
back to the top
Steps to Create a ScriptTemplate Template
A
ScriptTemplate template is part of the mobile
DeviceSpecific control. Any code that you include in the
ScriptTemplate is rendered immediately after the opening WML <card> tag.
The mobile
DeviceSpecific control includes a <Choice> tag. The <Choice> tag contains a filter attribute that uses the device filter that you created in the Web.config file. This filter is important because the code that is included in the
ScriptTemplate template does not adaptively render to the browsing device. Therefore, you must limit the
ScriptTemplate contents to only those devices that support the exact syntax that included in the template.
- Open a mobile Web form.
- Add the following code between the mobile form control tags (for example, between the <mobile:form runat="server" > tag and the </mobile:form> tag):
<mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
<Choice Filter="supports2SoftKeys" >
<ScriptTemplate>
<do type="options" label="MS">
<go href="www.microsoft.com" />
</do>
</ScriptTemplate>
</Choice>
</mobile:DeviceSpecific>
- Compile and run your application. Notice that the right softkey is available on devices that support the right softkey.
back to the top