Writing ASP applications for Pocket PCs

Paul Adams (paul@modezero.net), November 05, 2001.

Introduction

Active Server Pages (ASP) has provided an excellent environment for developers to rapidly create stable, feature rich, data driven applications. PocketASP brings this power the Pocket PC, enabling developers to apply their existing skills to an exciting new platform. This article explains how to get from installation through to creating a working PocketASP application.

Installation

The evaluation version of PocketASP is available from http://www.ModeZero.net/PocketASP.

It is fully functional and not time limited. If machine space is available, it is recommended that the ADOCE 3.1 version be downloaded as that contains the most up-to-date ADO drivers.

On The PC

  1. Download the zip file
  2. Unzip to a temporary location on the PC
  3. Open the readme.htm file for last minute information and the licence agreement
  4. Copy the .CAB file onto your Pocket PC

On the Pocket PC

  1. Close Pocket Internet Explorer if necessary
  2. Open Explorer and click on the .CAB file just copied down from the PC
  3. The required files will be copied and registered and the .CAB automatically removed

Now to test that the installation was successful:

  1. Open Pocket Internet Explorer
  2. If the Address Bar is not visible, click View->Address Bar
  3. Click on the text in the address bar and type pasp://ModeZero/
  4. The default homepage, "Welcome to PocketASP", will appear

Demonstration Pages

As a warm-up, before diving into creating your own pages, follow the link on the homepage to see the examples. Some of the key supported ASP objects and methods are demonstrated, such as:

Development Environment

The PocketASP project enables ASP developers to create their web applications in the normal way (on a PC) and then adds a new final stage of copying the pages down to the Pocket PC when the development is complete. The caveat is to be aware of currently supported objects and methods, as described in the release notes. For example, persistent cookies are supported, but per-session cookies are not, which means using the Session object to store session-based information.

While developing on the PC, it's possible to get an approximation of how the pages will look on the Pocket PC device. Using IE5, with View->Text Size set to Smallest, the following JavaScript creates a suitably sized window:

window.open("http://Machine/PocketASP/MyDomain/Default.htm", "PocketPCView", "toolbar=no,location=yes,directories=no,menubar=no,scrollbars=yes,resizable=no,width=252,height=275");

Hello World Example

An introduction to a platform would not be complete without a Hello World application. The example below was developed using Visual Interdev and tested on a machine running IIS, before being copied down to an iPaq H3630 for final testing.

Here's a step-by-step guide to getting an ASP page up and running.

1. Write the ASP code

Below is an example of some over-engineered code to output a Hello World message.
Hello.asp

<html> <body> <% sHello = "Hello" %> <hr> <p align="center"> <%= sHello & " " & WorldFn %> <p> <hr> <% '--------------------------------------- function WorldFn() WorldFn = "World!" end function '--------------------------------------- %> </body> </html>

2. Test It on the PC

Place the Hello.asp file into a virtual directory under IIS. Lets call it FirstExamples.

Navigating to http://MyMachine/FirstExamples/Hello.asp should result in a friendly Hello World! message appearing in your browser.

3. Create a new Pocket PC pseudo-domain

The installation process creates a directory called PAspPages in the root of the Pocket PC. The directories contained in \PAspPages are treated as pseudo-domains (for example ModeZero is created by the install for the demonstration pages). Note that, just like real domains, the pseudo-domain names should not contain spaces.

We need to create a new directory (pseudo-domain) under \PAspPages for our Hello World example page. Again, we'll use FirstExamples.

4. Copy to Pocket PC

Use Explorer to find the recently created /PAspPages/FirstExamples/ directory on the Pocket PC and copy Hello.asp from the PC to that directory.

5. Test it on the PocketPC

To see the finished product, open Pocket IE and type pasp://FirstExamples/Hello.asp. The same friendly message will appear on your browser.

The Hello World example shows that there are no tricks or hidden steps, the source files don't get mangled or transformed in any way (in fact, you could develop and edit them on the device). The only alteration that may be needed is to the look and feel of your pages to make allowances for the amount of screen space available.

Database Access

Including database functionality in your Pocket PC application is, again, business as usual for the ASP developer. The database support is provided using ADOCE, which is a subset of ADO. The core functionality of ADO is provided, i.e. adding, updating and removing information from tables.

Below are the steps to take to get your ASP application ready for database access:

  1. Design and create the database on the PC using Access
  2. Copy the .MDB file into a suitable directory on the Pocket PC using ActiveSync
  3. As part of the copy process ActiveSync will convert the database into a .CDB file
  4. In addition to the conversion ActiveSync also offers to keep the master (PC) database and the Pocket PC databases in sync.
  5. Write ASP pages using standard ADO connect and recordset calls.
    (note that the DSN for connection is just the path to the .CDB file created.)

For example:

Connect to Pocket PC Database

set oDBCon = Server.CreateObject("ADODB.Connection") oDBCon.ConnectionString = "data source = \PAspPages\ModeZero\_db\TestCEDB.cdb" oDBCon.Open

Open a Recordset

Set rs = Server.CreateObject("ADODB.RecordSet") rs.Open "PersonalInfo", oDBCon, 1, 3

(taken from the DemoDB.asp sample page)

Sessions And Cookies

If your application needs to store per-session or cross-session information then the Session and Cookie objects and methods are available and function in the usual way. The cookies use the pseudo-domain described above to define their scope, for example cookies in the ModeZero domain cannot be accessed from the FirstExamples domain.

Releasing Your Application

Finally, when it comes to releasing your application, developing in ASP means you are free from the current headache of compiling and maintaining versions over the different flavours of Pocket PC processor. The same code will run on all supported PocketASP platforms, making development and testing times shorter and source control simpler.

Summary

By using their existing skills, ASP developers can quickly create exciting new applications across the Pocket PC platforms. The database synchronisation features already provided by ActiveSync 3.1, coupled with the database support in PocketASP, enable access to a wealth of new data driven Pocket PC application opportunities. For many Pocket PC applications, developing in ASP will be quicker, more stable and easier to rollout than using the traditional alternatives.

Resources

Information on PocketASP can be found at http://www.ModeZero.net/PocketASP. There is also a discussion group on Yahoo! at http://groups.yahoo.com/group/PocketASP.

Related resources: