Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly
get the code
more resources

Use Mobile Controls
Translating a Web application to a phone version is easy with ASP.NET mobile controls.
by Bill Wagner

July 2003 Issue

Technology Toolbox: C#, ASP.NET, VS.NET 2003 final beta or newer, Microsoft Mobile Explorer Emulator

Microsoft's .NET vision enables you to develop and deploy your applications on an ever-wider array of platforms. For example, the ASP.NET mobile controls (known formerly as the Microsoft Mobile Internet Toolkit) let you deploy your Web applications on smartphones and other small-screen devices. In keeping with the .NET strategy, the ASP.NET mobile controls try to shield you from the differences among devices and let you concentrate on your business logic. I'll show you how to move a simple application from ASP.NET to mobile ASP.NET, explaining what you must change to make the application ready for the mobile Web (download the sample code here).

ADVERTISEMENT

You'll convert a simple Web application I built that predicts the weather at a few selected cities in the upper Midwest (see Figure 1). The data for the forecasts is completely random. (Using a random weather forecaster is about as accurate as any real forecast in this region. We just went from a high of 65 degrees to six feet of snow in two days.) I'll go into this application's design so you can see how to update your own applications. The application contains two VS.NET projects—WeatherLib and WeatherSite. WeatherLib contains the middle-tier logic. You create a Forecast object and simply use its indexer to retrieve the forecast. The application uses the ASP.NET Repeater control inside the form to retrieve the forecasts for the next 10 days (see Listing 1). The DataBinder.Eval() method returns a formatted string for the property that describes each element of the forecast.

Now it's time to convert this application to ASP.NET mobile controls. I tried to separate the middle-tier logic in WeatherLib from the presentation layer in WeatherSite, even though this is a small sample. You should strive for the same separation in your applications. I haven't shown you any code in the code-behind class, because there's not much there. All the code-behind class does is create the middle-tier objects and query them for properties.

You'll adopt the strategy of directing mobile users to a different site. Use the VS.NET wizard to create a new project. Select "ASP.NET Mobile Web Application" under the C# tab. VS.NET creates a new application with one page, exactly like a regular ASP.NET application. However, the generated files contain a few differences. First, web.config includes two new sections—MobileControls and DeviceFilters. MobileControls contains a key to support cookieless data dictionaries. This setting means that the dictionary contents are stored in the query string so that session and authentication work properly on mobile devices. The deviceFilters section is much larger and provides several capabilities ASP.NET uses to create device-specific content. You must add or modify this section if you add your own device-specific content. The default section is sufficient in most cases.

Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home