Note

Server validation controls used within mobile Web applications always execute on the server. However, in standard ASP.NET, you can execute some of the validation controls on the client by using client-side script. You can't do this with mobile applications, even if you know that a client supports client-side script. The validation controls use StyleReference error by default, which on an HTML browser displays the associated error message in red. You can use the style properties inherited from...

Deploying and Consuming an XML Web Service

The simplest way to deploy an XML Web service is to leave the .asmx file in the virtual directory on your Web server. You deploy XML Web services that you build using Visual Studio .NET in exactly the same way as an ASP.NET application, either by using the Copy Project facility or by building a Visual Studio .NET setup and deployment project (as described in Chapter 14). You can call this XML Web service from a Web browser and access its Web methods, as Figure 12-2 shows. However, in real life,...

Special Purpose Controls

The Mobile Internet Toolkit supplies three special-purpose controls to assist you in building feature-rich mobile Web applications the Calendar, PhoneCall, and AdRotator controls. Figure 7-1 shows the complete set of specialpurpose controls and their relationship to the other mobile classes. Figure 7-1. Class hierarchy of the special-purpose controls Figure 7-1. Class hierarchy of the special-purpose controls The Calendar control, which provides date-picking functionality, is a powerful tool....

Binding to a Data Collection

Although static lists have their uses, invariably your applications will work with items from a data collection. The ObjectList control must be bound to a data collection because it doesn't support statically defined items. You can bind the controls that support data binding to two types of data sources those that support the IEnumerable interface, and those that support IListSource. Many of the collection classes supplied in the .NET Framework support the IEnumerator interface and consequently...

Window lists all the files in a project

For a Mobile Web Application project, Solution Explorer will now display the following items Solution This entry is at the top of the tree in Solution Explorer. The related disk file has an .sln extension. The .sln file contains information about your project and some general information about your solution. When you create a new project, you'll see two radio buttons on the New Project dialog box. These allow you to close the current solution and create a project in a new solution (the...

Developing Web Applications

An ASP.NET Web application typically contains Web Forms containing server controls, program modules containing application logic, and other supporting resources, such as XML configuration files. Armed with these resources, developing Web applications with ASP.NET starts to feel quite similar to the way Visual Basic developers have developed applications over recent years, using drag-and-drop GUI development and programming against events. In this section, we'll examine ASP.NET Web development....

Building Multilingual and Multicultural Mobile Web Applications

You can increase the usability of your application in certain parts of the world by offering an interface that's translated into the user's preferred language as well as formatting currency and dates according to cultural norms. ASP.NET has a number of features to help you build applications that provide content appropriate for a specific culture. When considering applications for users in different regions of the world, don't make the mistake of thinking that you only need to translate the...

Text Box Controls

The TextBox control enables single-line input. Using this control, you can either display an initial default value or allow user input to modify or replace that initial value. You code the TextBox control in server control syntax, as shown here. Only the most commonly used attributes are listed. The common style attributes, such as Font-* BackColor and ForeColor, are ignored when the TextBox is rendered, so they're not listed here. The wmlFormat attribute is a custom attribute used for defining...

Support

Every effort has been made to ensure the accuracy of this book. Microsoft Press provides corrections for books through the World Wide Web at the following address To connect directly to the Microsoft Press Knowledge Base and enter a query regarding a question or issue that you may have, go to If you have comments, questions, or ideas regarding this book, please send them to Microsoft Press using either of the following methods Microsoft Press Attn Building .NET Applications for Mobile Devices...

Text View Controls

The TextView control allows you to display text that's too long for the Label control. Unlike Label, TextView supports internal pagination, so very long blocks of text are split across multiple display pages when the enclosing Form control has pagination enabled. TextView also supports optional markup tags, in the same way as literal text on a Form control. In server control syntax, you code the TextView control like this runat server id id Alignment NotSet Left Centre Right BackColor...

Identifying the Device

The most common way to identify a device is to test the HTTP User-Agent request header with a regular expression. However, you can use any valid HTTP request header when determining the type of a new client. For example, some devices host dual-mode browsers that can handle both Wireless Markup Language (WML) and HTML, so filtering on the User-Agent header is sufficient to distinguish between them. However, if the User-Agent string is the same, you can first use the User-Agent header to...

Defining a Device Adapter

We mentioned that you might want to write new device adapter classes for a number of reasons. For example, you might want to replace the standard device adapter with a customized version , or you might want to add device adapters that support custom controls. (As you learned in Chapter 15, user controls and custom controls built by inheritance or by composition use the device adapters of the standard controls from which they derive, and they rarely have custom device adapters. Controls built...

Supporting Localized Content

The text an application displays originates from many different Mobile Internet Toolkit class objects. You can set all the text at runtime using properties of the class objects. The following are some of the most common types of text you'll set for a localized application and the properties you'll use to do so You can set static text displayed in the Label and TextView controls at runtime by using the Text property. You can use the Text property of the MobileListItem object to set the...

Click To Nokia 7110 Emulator

The Pocket PC emulator that's shipped in eMbedded Visual Tools 3.0 doesn't include JScript support by default, which is required for some Mobile Internet Toolkit applications. You must download emulation support from the MSDN download center. See for details. If you haven't worked with a Pocket PC before, you'll notice that the Start button appears in the top-left corner of the screen rather than the bottom-left corner, as on a desktop PC. Click Start in the emulation, and click Internet...

Listing 819 Codebehind file Object ListItem DetailsTemplate Exampleaspxcs

Private int _position, _played, _won, _drawn, _lost, _points public TeamStats(String teamName, int position, int played, int won, int drawn, int lost, int points) this._teamName teamName this._position position this._played played this._won won this._drawn drawn this._lost lost this._points points public class MyWebForm System.Web.UI.MobileControls.MobilePage protected void Page_Load(Object sender, EventArgs e) ArrayList array new ArrayList() array.Add(new array.Add(new array.Add(new...

Where Is Code 017943

In Visual Studio .NET, you can edit the Web.config file for an application directly. Double-click on the file Web.Config in Solution Explorer, and Visual Studio .NET opens an editor window. Another convenient way to make changes to this file is to view a Mobile Web Form in Design view in the Mobile Internet Designer. If you click on the background outside any Form control, the Properties window displays properties of the DOCUMENT. Many of the properties displayed here, such as debug, trace, and...

Using the Session Object

Typically, you'll manipulate the Session object either in the code-behind module of your application's Global.asax file or the code-behind module of your mobile Web Forms page. Like mobile Web Forms pages, the Global.asax file supports a code-behind module. This module follows the naming convention global.asax.extension, where extension indicates the programming language used. For example, you'd name a C code-behind module Global.asax.cs. The application in Listing 10-1 adds a string...

Defining Culture for Formatting Strings Dates and Times

By defining a culture, you influence the formatting style of methods that your application uses to output information, such as strings, dates, and number formats. If you don't specify any culture settings, the application uses the locale settings of the Web server. However, it's good practice to specify culture settings explicitly. A mobile Web Forms page has two culture settings that can be declared in the Page directive Culture attribute This setting ensures that the runtime formats...

Property or Public Data Member

The xmlList control shown in Listing 15-7 defines the XMLsource property. In this example, this property is coded using get and set accessors, which don't implement any extra logic in this case. You could just as easily make the XMLsource property a public data member of the class without any visible difference to the control's users. Whether or not you implement properties of a class that have no associated validation logic public data members is really up to you. However, it's good practice...

Hidden Variables

Sometimes you might want to pass small amounts of information between Web pages without using session state. For example, suppose you need to collect information from a multipart form that the user fills in. In HTML, you'd pass the information from one page to another using input tags with a type value of hidden. But in Wireless Markup Language (WML), you'd set variables in the browser's cache and then post all their values to the server when the user completed the forms. TheMobilePage class's...

Working with the Device Adapter Sources

Creating a new project in Microsoft Visual Studio .NET is the easiest way to work with device adapters. You add the existing Microsoft-supplied device adapter sources to the project, modify the source code, and write your own device adapter classes. You then compile all the code into a new assembly that you can deploy on your Web server and use in your applications. Here are the steps you need to take 1. In Visual Studio .NET, create a new Visual C project of type Class Library. Name it Custom...

Supporting New Clients

In most instances, ASP.NET delivers your mobile Web Forms pages to clients the way you expect. However, this isn't always the case. Your handheld device might report an error when you try to access an application, or the application might not display correctly on the device. The most likely reason is that the runtime doesn't support the device in question. Think about how many browsers and versions of them run on such a wide variety of devices it probably won't surprise you that the Mobile...

Building a Data Bound Custom Control

A table control that displays only a single row isn't very useful. A table control becomes truly useful when you can data bind it so that items from an array or collection provide the data listed. We'll now build the CMTableDB control that implements data binding and a SelectionList or List control that forms the basis of its design. To support data binding, you perform the following steps 1. Add a property of type ICollection in which you specify the datasource. Call this property DataSource...

Using a Data Component in a Web Application

When you remove all the data-handling code from the component, the main application class becomes much cleaner and can focus on the logic required to drive the user interface. To prepare a component for use in a Web application, open the DataUpdateExample project you used in the previous example or use the Copy Project feature to make a copy, naming it DataComponentExample. Then open the copy, as described in Chapter 3 in the section Working with Visual Studio .NET Projects. To use the data...

Testing with Emulators and Real Devices

In Chapter 3, you learned how to test your applications using Internet Explorer and the Openwave simulator. The use of the WML or cHTML browser of your choice alongside Internet Explorer might prove sufficient for much of your initial application testing. However, if you expect your users to access your application from different devices, you should test with emulators of those devices and, ultimately, with the actual devices. Although the software emulator tools often embed the actual browser...

Simple Control with Device Adapters for HTML and WML

The control shown in Listing 16-1 allows the page developer to specify the column 1 and column 2 text values as properties. An additional property allows you to specify a Title string, which some WML browsers display at the head of a table. At present, you can output only a single table row. This control inherits from System.Web.UI. MobileControls.MobileControl and needs very little code to provide basic functionality. Listing 16-1 Simple control that allows you to specify a Title property as...

Using Aspnet Declarative Data Binding

Many of the examples introduced in earlier chapters in the book included data expressions in the mobile Web Forms page, enclosed in these tags lt gt . This ASP.NET declarative data binding syntax is particularly useful in templates when you want to access data items in the underlying data collection. However, you can also use this syntax to achieve the following results Insert the values of public variables, page properties, or other controls. Specify the collections to which controls are...

Application 1 Hello Universe

In this first sample application, you'll expand on the customary Hello World Web Forms page that you created in Chapter 3 to build a Hello Universe Web application. Although simple, this application illustrates a number of important features of building .NET mobile Web applications, including these Using the code-behind technique Capturing events fired by mobile controls Dynamically altering the properties of controls within Web Forms Working with the object-oriented methodology of .NET...

Listing 111 Redirect page to route clients to a Web Forms page or a mobile Web Forms page as appropriate

lt Page language c gt lt Register TagPrefix mobile Assembly System.Web.Mobile gt lt script language C runat server gt public void Page_Load Object sender, EventArgs e If the code names this page Default.aspx and Microsoft Internet Information Services IIS recognizes that name as a default document as it does by default , users need only enter the URL up to the application name for example, http MyWebServer MyApplication. Another convenience of this design approach When using Response.Redirect...

Debugging Mobile Web Applications

When you build an application during development, the compiler ensures that the code defined in code-behind class modules and other classes compiles correctly. Despite this built-in debugging, when you run your application, several other types of errors can occur Configuration errors Parsing errors that occur in one of the configuration files Machine.config in the directory, the server-wide Web.config file in the Web server wwwroot directory, or Web.config in the application root directory....

Understanding the IState Manager Interface

SaveViewState and LoadViewState are required methods of the IStateManager interface. You can also implement a third method of this interface, TrackChanges, which you call to instruct a server control to track changes to its state. The IsTrackingViewState property returns a Boolean value to indicate whether the control is tracking state. Together, these methods and this property make up the IStateManager interface. The page framework uses this interface to handle the saving and restoration of...

Using Custom Controls and Device Adapters

The procedure for using a custom control built from scratch is essentially the same as the procedure for using controls built by inheritance or composition. You add references to the assemblies that contain the custom controls and device adapters to your mobile Web project. And you use and declare custom mobile controls in the same way, as Listing 16-4 shows. Listing 16-4 Mobile Web Forms page using the CMsimple one-row table control lt Register TagPrefix CMcustom gt lt Register TagPrefix...

Figure 38 Testing a mobile Web application with the Openwave simulator

Openwave Simulator Windows

Go http7 localhost MyFirstMobileApp defau Go http7 localhost MyFirstMobileApp defau Actual WAP devices always connect to the Internet via a special proxy, called a WAP gateway. This gateway acts as an important bridge between the wireless WAP protocols used by the phone and the HTTP over TCP IP used by the wired Web. When you test with a real device, you must configure it to connect via a WAP gateway, operated by your wireless service provider, or in some cases, your company. Fortunately, the...

Listing 99 Data UpdateExampleaspx

lt Page language c AutoEventWireup true gt lt Register TagPrefix mobile Assembly System.Web.Mobile gt lt mobile Form id Form1 runat server Paginate True gt lt mobile ObjectList id ObjectList1 runat server OnItemCommand OnEditCommand gt lt Command Name EditCommand Text Edit Details gt lt mobile ObjectList gt lt mobile Form gt lt mobile Form id Form2 runat server gt lt mobile Label id Label1 runat server text Edit Author Details StyleReference title gt lt mobile Label runat server gt Author ID...

Defining XML Web Service Behavior

When you created your first XML Web service, you placed a WebMethod directive before the method you wanted to make publicly accessible as a Web method. This directive accepts a number of optional attributes that allow you to define certain behaviors and characteristics of the XML Web service method. Table 12-1 outlines the most common attributes of this directive. Table 12-1. Common Attributes of the WebMethod Directive Table 12-1. Common Attributes of the WebMethod Directive When the value is...

Viewing Data Set XML in Internet Explorer

If the format of a DataSet returned as XML interests you, you can view the XML using a desktop Web browser. Simply type the URL of the XML Web service you want to use into the Address box, followed by MethodName , where MethodName is the name of a method that returns a DataSet. Remember, you're accessing the XML Web service using one of the supported open standards HTTP GET. The XML response returns to the browser. Browsers with integral XML support, such as Internet Explorer will format and...

Warning

The names of the XML elements in the advertisement configuration file are case sensitive. For example, lt ImageUrl gt is a valid XML element name, but lt ImageURL gt isn't. lt xml version l.0 gt lt AlternateText gt Buy this lt AlternateText gt lt Keyword gt Software lt Keyword gt lt Ad gt lt Another advertisement defined here -- gt lt mobile AdRotator runat server id id Font-Size NotSet Normal Small Large Font-Bold NotSet False True Font-Italic NotSet False True ForeColor foregroundColor...

Wireless Communication

Wireless communication has long captivated the imagination of consumers. Even as far back as the 1920s, wireless technology was everywhere. For example, a huge expansion of radio broadcasting was underway, fueled by the money of eager investors many of whom soon regretted their enthusiasm once the stock market crashed in 1929 . Unlike broadcast radio, which sends the same message to multiple receiving devices, paging and cellular phone communications use wireless technology to communicate with...

Creating User Controls and Custom Controls

The Mobile Internet Toolkit provides a rich selection of mobile controls that offer the functionality you need to build compelling mobile Web applications. However, you might find yourself repeatedly implementing the same piece of user interface functionality, using the same combination of controls. By encapsulating this user interface functionality in a reusable component, you can take advantage of a major strength of ASP.NET user controls. User controls are easy to build and to apply. But for...

Implementing the OnData Bind Event

You add public events to your control the same way you do for controls built by inheritance or composition. The standard data bound controls expose the ItemDataBind event, which an application developer can trap to implement custom data binding. It makes sense to implement this event for our custom control. To implement the ItemDataBind event, declare a public delegate for the event handler. You declare this delegate in a source file, inside the namespace but outside any class definitions...

Dynamic Mobile Applications

In Chapter 3, you learned how to build several simple mobile Web applications. In this chapter, you'll learn how to create dynamic mobile applications. Creating dynamic mobile applications involves writing code to manipulate the methods and properties of mobile Web Forms controls and to respond to the events those methods and properties raise. In this chapter, we'll show you how to choose a .NET programming language and adopt a coding technique. We'll also introduce you to Visual C ,...

Extensible Device Support Architecture

The first release of the Mobile Internet Toolkit supports a number of WML 1.1 and WML 1.2 devices, HTML 3.2 clients such as Pocket Internet Explorer, and cHTML 1.0 devices. The toolkit's device support architecture is extensible. Therefore, updates to the toolkit will undoubtedly support additional genres, such as WML 2.0 and cHTML 1.1. If you don't want to wait for Microsoft to release support for a new device, you can add the necessary support yourself. In addition, Microsoft recognizes that...

Setting Up the Openwave Simulator

Openwave Simulator Windows

Openwave is the company formed from the merger of Phone.com and Software.com. Phone.com was itself formerly known as Unwired Planet, which was responsible for devising the HDML markup language for mobile devices, a predecessor of WAP. Today, Openwave claims that 70 percent of the world's Internet-enabled phones use their mobile browser software. The Mobile Internet Toolkit version 1.0 release includes support for devices from Alcatel, Motorola, Samsung, Sanyo, Siemens, Panasonic, Casio, Denso,...

Understanding Naming Containers

Developers frequently use declarative data binding in templates that customize the output of the List and ObjectList controls. The lt ItemTemplate gt and lt AlternatingItemTemplate gt replace the normal rendering of an item displayed in a list, so you need to access the properties of the source data item you're displaying in order to display the list item. To do so, you must understand the correct naming syntax. Accessing Data Items in lt ItemTemplate gt and lt AlternatingItemTemplate gt...

Selection List Controls

As we mentioned, this control is appropriate for displaying small lists of items. It doesn't support internal pagination, but it offers presentational options that allow you to include drop-down lists, combo boxes, and radio buttons on devices that support them. The control is in single-selection mode when the SelectType is DropDown, ListBox, or Radio. CheckBox or MultiSelectListBox indicates multiselect mode. The SelectionList is used declaratively as shown in this section. Items that display...

Testing with a Mobile Phone Emulator

You'll find Internet Explorer an adequate development tool for performing the initial testing of an application's functionality. However, one of the most powerful features of the Mobile Internet Toolkit is that it can render your application on different client browsers, each with its own capabilities and possibly even requiring a completely different markup language. You should test your application on devices that are likely to access it in the real world. You use the mobile Web Forms...